genericunixprotocols/ftpsrv/src/ftpcmd.y
author bdonegan
Thu, 30 Sep 2010 16:15:48 +0100
changeset 3 b667e5204120
parent 0 c6b0df440bee
permissions -rw-r--r--
Remove reference to cinidata in order to allow TrkEngine to build
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     1
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     2
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     3
// All rights reserved.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     4
// This component and the accompanying materials are made available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     5
// under the terms of the License "Eclipse Public License v1.0"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     6
// which accompanies this distribution, and is available
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     7
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     8
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
     9
// Initial Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    10
// Nokia Corporation - initial contribution.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    11
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    12
// Contributors:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    13
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    14
// Description:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    15
//
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    16
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    17
/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    18
 * Copyright (c) 1985, 1988, 1993, 1994
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    19
 *	The Regents of the University of California.  All rights reserved.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    20
 *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    21
 * Redistribution and use in source and binary forms, with or without
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    22
 * modification, are permitted provided that the following conditions
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    23
 * are met:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    24
 * 1. Redistributions of source code must retain the above copyright
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    25
 *    notice, this list of conditions and the following disclaimer.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    26
 * 2. Redistributions in binary form must reproduce the above copyright
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    27
 *    notice, this list of conditions and the following disclaimer in the
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    28
 *    documentation and/or other materials provided with the distribution.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    29
 * 3. All advertising materials mentioning features or use of this software
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    30
 *    must display the following acknowledgement:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    31
 *	This product includes software developed by the University of
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    32
 *	California, Berkeley and its contributors.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    33
 * 4. Neither the name of the University nor the names of its contributors
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    34
 *    may be used to endorse or promote products derived from this software
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    35
 *    without specific prior written permission.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    36
 *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    37
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    38
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    39
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    40
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    41
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    42
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    43
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    44
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    45
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    46
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    47
 * SUCH DAMAGE.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    48
 *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    49
 *	@(#)ftpcmd.y	8.3 (Berkeley) 4/6/94
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    50
 *	NetBSD: ftpcmd.y,v 1.7 1996/04/08 19:03:11 jtc Exp
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    51
 *	OpenBSD: ftpcmd.y,v 1.16 1998/05/22 06:46:09 deraadt Exp
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    52
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    53
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    54
/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    55
 * Grammar for FTP commands.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    56
 * See RFC 959.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    57
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    58
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    59
%{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    60
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    61
char ftpcmd_rcsid[] = 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    62
  "$Id: ftpcmd.y,v 1.11 1999/10/09 02:32:12 dholland Exp $";
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    63
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    64
#include <sys/param.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    65
#include <sys/socket.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    66
#include <sys/stat.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    67
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    68
#include <netinet/in.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    69
#include <arpa/ftp.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    70
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    71
#include <ctype.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    72
#include <errno.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    73
#include <glob.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    74
#include <pwd.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    75
#include <setjmp.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    76
#include <signal.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    77
#include <stdio.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    78
#include <stdlib.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    79
#include <string.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    80
#include <syslog.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    81
#include <time.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    82
#include <unistd.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    83
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    84
#ifndef __linux__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    85
#include <tzfile.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    86
#else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    87
#define TM_YEAR_BASE 1900
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    88
#endif
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    89
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    90
#include "extern.h"
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    91
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    92
extern	struct sockaddr_in data_dest;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    93
extern	int logged_in;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    94
extern	struct passwd *pw;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    95
extern	int guest;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    96
extern	int logging;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    97
extern	int type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    98
extern	int form;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
    99
extern	int debug;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   100
extern	int timeout;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   101
extern	int maxtimeout;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   102
extern  int pdata;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   103
extern	char hostname[], remotehost[];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   104
extern	char proctitle[];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   105
extern	int usedefault;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   106
extern  int transflag;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   107
extern  char tmpline[];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   108
extern	int portcheck;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   109
extern	struct sockaddr_in his_addr;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   110
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   111
off_t	restart_point;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   112
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   113
static	int cmd_type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   114
static	int cmd_form;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   115
static	int cmd_bytesz;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   116
char	cbuf[512];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   117
char	*fromname;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   118
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   119
struct tab;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   120
static int	 yylex __P((void));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   121
//static void	 sizecmd __P((char *));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   122
static void	 help __P((struct tab *, char *));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   123
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   124
extern struct tab cmdtab[];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   125
extern struct tab sitetab[];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   126
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   127
%}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   128
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   129
%union {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   130
	int	i;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   131
	char   *s;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   132
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   133
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   134
%token
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   135
	A	B	C	E	F	I
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   136
	L	N	P	R	S	T
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   137
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   138
	SP	CRLF	COMMA
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   139
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   140
	USER	PASS	ACCT	REIN	QUIT	PORT
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   141
	PASV	TYPE	STRU	MODE	RETR	STOR
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   142
	APPE	MLFL	MAIL	MSND	MSOM	MSAM
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   143
	MRSQ	MRCP	ALLO	REST	RNFR	RNTO
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   144
	ABOR	DELE	CWD	LIST	NLST	SITE
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   145
	STAT	HELP	NOOP	MKD	RMD	PWD
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   146
	CDUP	STOU	SMNT	SYST	SIZE	MDTM
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   147
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   148
	UMASK	IDLE	CHMOD
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   149
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   150
	LEXERR
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   151
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   152
%token	<s> STRING
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   153
%token	<i> NUMBER
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   154
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   155
%type	<i> check_login octal_number byte_size
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   156
%type	<i> struct_code mode_code type_code form_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   157
%type	<s> pathstring pathname password username
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   158
%type	<i> host_port
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   159
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   160
%start	cmd_list
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   161
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   162
%%
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   163
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   164
cmd_list
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   165
	: /* empty */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   166
	| cmd_list cmd
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   167
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   168
			fromname = (char *) 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   169
			restart_point = (off_t) 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   170
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   171
	| cmd_list rcmd
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   172
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   173
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   174
cmd
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   175
	: USER SP username CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   176
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   177
			user($3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   178
			free($3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   179
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   180
	| PASS SP password CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   181
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   182
			pass($3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   183
			memset($3, 0, strlen($3));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   184
			free($3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   185
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   186
	| PORT check_login SP host_port CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   187
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   188
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   189
				if ($4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   190
					usedefault = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   191
					reply(500,	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   192
					    "Illegal PORT rejected (range errors).");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   193
				} else if (portcheck &&
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   194
				    ntohs(data_dest.sin_port) < IPPORT_RESERVED) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   195
					usedefault = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   196
					reply(500,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   197
					    "Illegal PORT rejected (reserved port).");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   198
				} else if (portcheck &&
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   199
				    memcmp(&data_dest.sin_addr,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   200
				    &his_addr.sin_addr,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   201
				    sizeof data_dest.sin_addr)) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   202
					usedefault = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   203
					reply(500,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   204
					    "Illegal PORT rejected (address wrong).");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   205
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   206
					usedefault = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   207
					if (pdata >= 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   208
						(void) close(pdata);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   209
						pdata = -1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   210
					}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   211
					reply(200, "PORT command successful.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   212
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   213
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   214
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   215
	| PASV check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   216
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   217
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   218
				passive();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   219
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   220
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   221
	| TYPE check_login SP type_code CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   222
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   223
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   224
				switch (cmd_type) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   225
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   226
				case TYPE_A:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   227
					if (cmd_form == FORM_N) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   228
						reply(200, "Type set to A.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   229
						type = cmd_type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   230
						form = cmd_form;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   231
					} else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   232
						reply(504, "Form must be N.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   233
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   234
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   235
				case TYPE_E:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   236
					reply(504, "Type E not implemented.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   237
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   238
	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   239
				case TYPE_I:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   240
					reply(200, "Type set to I.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   241
					type = cmd_type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   242
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   243
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   244
				case TYPE_L:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   245
					if (cmd_bytesz == 8) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   246
					       reply(200,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   247
					       "Type set to L (byte size 8).");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   248
					       type = cmd_type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   249
					} else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   250
					    reply(504, "Byte size must be 8.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   251
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   252
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   253
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   254
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   255
	| STRU check_login SP struct_code CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   256
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   257
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   258
				switch ($4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   259
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   260
				case STRU_F:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   261
					reply(200, "STRU F ok.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   262
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   263
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   264
				default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   265
					reply(504, "Unimplemented STRU type.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   266
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   267
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   268
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   269
	| MODE check_login SP mode_code CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   270
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   271
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   272
				switch ($4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   273
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   274
				case MODE_S:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   275
					reply(200, "MODE S ok.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   276
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   277
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   278
				default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   279
					reply(502, "Unimplemented MODE type.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   280
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   281
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   282
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   283
	| ALLO check_login SP NUMBER CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   284
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   285
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   286
				reply(202, "ALLO command ignored.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   287
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   288
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   289
	| ALLO check_login SP NUMBER SP R SP NUMBER CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   290
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   291
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   292
				reply(202, "ALLO command ignored.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   293
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   294
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   295
	| RETR check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   296
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   297
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   298
				retrieve((char *) 0, $4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   299
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   300
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   301
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   302
	| STOR check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   303
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   304
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   305
				store($4, "w", 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   306
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   307
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   308
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   309
	| APPE check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   310
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   311
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   312
				store($4, "a", 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   313
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   314
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   315
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   316
	| NLST check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   317
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   318
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   319
				send_file_list(".",1);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   320
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   321
	| NLST check_login SP STRING CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   322
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   323
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   324
				send_file_list($4,1);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   325
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   326
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   327
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   328
	| LIST check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   329
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   330
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   331
				send_file_list(".",0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   332
				//retrieve("/bin/ls -lgA", "");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   333
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   334
	| LIST check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   335
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   336
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   337
				send_file_list($4,0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   338
				//retrieve("/bin/ls -lgA %s", $4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   339
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   340
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   341
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   342
	| STAT check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   343
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   344
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   345
				statfilecmd($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   346
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   347
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   348
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   349
	| STAT check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   350
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   351
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   352
				statcmd();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   353
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   354
	| DELE check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   355
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   356
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   357
				dele($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   358
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   359
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   360
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   361
	| RNTO check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   362
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   363
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   364
				if (fromname) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   365
					renamecmd(fromname, $4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   366
					free(fromname);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   367
					fromname = (char *) 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   368
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   369
					reply(503, 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   370
					  "Bad sequence of commands.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   371
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   372
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   373
			free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   374
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   375
	| ABOR check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   376
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   377
			if ($2) 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   378
				reply(225, "ABOR command successful.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   379
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   380
	| CWD check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   381
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   382
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   383
				cwd(pw->pw_dir);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   384
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   385
	| CWD check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   386
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   387
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   388
				cwd($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   389
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   390
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   391
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   392
	| HELP CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   393
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   394
			help(cmdtab, (char *) 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   395
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   396
	| HELP SP STRING CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   397
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   398
			char *cp = $3;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   399
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   400
			if (strncasecmp(cp, "SITE", 4) == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   401
				cp = $3 + 4;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   402
				if (*cp == ' ')
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   403
					cp++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   404
				if (*cp)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   405
					help(sitetab, cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   406
				else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   407
					help(sitetab, (char *) 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   408
			} else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   409
				help(cmdtab, $3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   410
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   411
			if ($3 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   412
				free ($3);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   413
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   414
	| NOOP CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   415
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   416
			reply(200, "NOOP command successful.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   417
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   418
	| MKD check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   419
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   420
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   421
				makedir($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   422
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   423
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   424
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   425
	| RMD check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   426
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   427
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   428
				removedir($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   429
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   430
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   431
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   432
	| PWD check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   433
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   434
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   435
				pwd();
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   436
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   437
	| CDUP check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   438
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   439
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   440
				cwd("..");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   441
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   442
	| SITE SP HELP CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   443
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   444
			help(sitetab, (char *) 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   445
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   446
	| SITE SP HELP SP STRING CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   447
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   448
			help(sitetab, $5);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   449
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   450
			if ($5 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   451
				free ($5);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   452
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   453
	| SITE SP UMASK check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   454
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   455
			int oldmask;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   456
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   457
			if ($4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   458
				oldmask = umask(0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   459
				(void) umask(oldmask);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   460
				reply(200, "Current UMASK is %03o", oldmask);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   461
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   462
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   463
	| SITE SP UMASK check_login SP octal_number CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   464
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   465
			int oldmask;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   466
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   467
			if ($4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   468
				if (($6 == -1) || ($6 > 0777)) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   469
					reply(501, "Bad UMASK value");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   470
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   471
					oldmask = umask($6);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   472
					reply(200,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   473
					    "UMASK set to %03o (was %03o)",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   474
					    $6, oldmask);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   475
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   476
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   477
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   478
	| SITE SP CHMOD check_login SP octal_number SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   479
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   480
			if ($4 && ($8 != NULL)) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   481
				if ($6 > 0777)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   482
					reply(501,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   483
				"CHMOD: Mode value must be between 0 and 0777");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   484
				else if (chmod($8, $6) < 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   485
					perror_reply(550, $8);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   486
				else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   487
					reply(200, "CHMOD command successful.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   488
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   489
			if ($8 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   490
				free($8);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   491
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   492
	| SITE SP check_login IDLE CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   493
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   494
			if ($3)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   495
			  reply(200,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   496
	       		    "Current IDLE time limit is %d seconds; max %d",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   497
				timeout, maxtimeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   498
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   499
	| SITE SP check_login IDLE SP NUMBER CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   500
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   501
			if ($3) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   502
				if ($6 < 30 || $6 > maxtimeout) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   503
				reply(501,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   504
	       		 "Maximum IDLE time must be between 30 and %d seconds",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   505
				    maxtimeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   506
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   507
					timeout = $6;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   508
					(void) alarm((unsigned) timeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   509
					reply(200,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   510
					 "Maximum IDLE time set to %d seconds",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   511
					    timeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   512
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   513
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   514
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   515
	| STOU check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   516
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   517
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   518
				store($4, "w", 1);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   519
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   520
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   521
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   522
	| SYST check_login CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   523
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   524
			if ($2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   525
#ifdef __linux__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   526
			reply(215, "UNIX Type: L%d (Linux)", CHAR_BIT);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   527
#else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   528
#ifdef unix
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   529
#ifdef BSD
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   530
			reply(215, "UNIX Type: L%d Version: BSD-%d",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   531
				CHAR_BIT, BSD);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   532
#else /* BSD */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   533
			reply(215, "UNIX Type: L%d", CHAR_BIT);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   534
#endif /* BSD */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   535
#else /* unix */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   536
#ifdef __SYMBIAN32__		
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   537
			reply(215, "UNIX Type: L%d", CHAR_BIT);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   538
#else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   539
			reply(215, "UNKNOWN Type: L%d", CHAR_BIT);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   540
#endif /* __symbian32__ */	
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   541
#endif /* unix */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   542
#endif /* __linux__ */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   543
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   544
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   545
		/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   546
		 * SIZE is not in RFC959, but Postel has blessed it and
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   547
		 * it will be in the updated RFC.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   548
		 *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   549
		 * Return size of file in a format suitable for
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   550
		 * using with RESTART (we just count bytes).
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   551
		 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   552
	| SIZE check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   553
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   554
			if ($2 && $4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   555
				sizecmd($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   556
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   557
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   558
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   559
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   560
		/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   561
		 * MDTM is not in RFC959, but Postel has blessed it and
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   562
		 * it will be in the updated RFC.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   563
		 *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   564
		 * Return modification time of file as an ISO 3307
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   565
		 * style time. E.g. YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   566
		 * where xxx is the fractional second (of any precision,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   567
		 * not necessarily 3 digits)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   568
		 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   569
	| MDTM check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   570
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   571
			if ($2 && $4 != NULL) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   572
				struct stat stbuf;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   573
				if (stat($4, &stbuf) < 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   574
					reply(550, "%s: %s",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   575
					    $4, strerror(errno));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   576
				else if (!S_ISREG(stbuf.st_mode)) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   577
					reply(550, "%s: not a plain file.", $4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   578
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   579
					struct tm *t;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   580
					t = gmtime(&stbuf.st_mtime);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   581
					reply(213,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   582
					    "%04d%02d%02d%02d%02d%02d",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   583
					    TM_YEAR_BASE + t->tm_year,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   584
					    t->tm_mon+1, t->tm_mday,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   585
					    t->tm_hour, t->tm_min, t->tm_sec);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   586
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   587
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   588
			if ($4 != NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   589
				free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   590
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   591
	| QUIT CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   592
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   593
			reply(221, "Goodbye.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   594
			dologout(0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   595
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   596
	| error CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   597
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   598
			yyerrok;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   599
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   600
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   601
rcmd
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   602
	: RNFR check_login SP pathname CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   603
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   604
			restart_point = (off_t) 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   605
			if ($2 && $4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   606
				fromname = renamefrom($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   607
				if (fromname == (char *) 0 && $4) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   608
					free($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   609
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   610
			} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   611
				if ($4)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   612
					free ($4);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   613
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   614
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   615
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   616
	| REST check_login SP byte_size CRLF
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   617
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   618
			if ($2) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   619
			    fromname = (char *) 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   620
			    restart_point = $4;	/* XXX $4 is only "int" */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   621
			    reply(350, "Restarting at %qd. %s", 
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   622
			       (quad_t) restart_point,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   623
			       "Send STORE or RETRIEVE to initiate transfer.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   624
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   625
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   626
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   627
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   628
username
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   629
	: STRING
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   630
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   631
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   632
password
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   633
	: /* empty */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   634
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   635
			$$ = (char *)calloc(1, sizeof(char));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   636
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   637
	| STRING
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   638
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   639
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   640
byte_size
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   641
	: NUMBER
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   642
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   643
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   644
host_port
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   645
	: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   646
		NUMBER COMMA NUMBER
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   647
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   648
			char *a, *p;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   649
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   650
			if ($1 < 0 || $1 > 255 || $3 < 0 || $3 > 255 ||
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   651
			    $5 < 0 || $5 > 255 || $7 < 0 || $7 > 255 ||
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   652
			    $9 < 0 || $9 > 255 || $11 < 0 || $11 > 255) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   653
				$$ = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   654
			} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   655
#ifndef __linux__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   656
				data_dest.sin_len = sizeof(struct sockaddr_in);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   657
#endif
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   658
				data_dest.sin_family = AF_INET;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   659
				p = (char *)&data_dest.sin_port;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   660
				p[0] = $9; p[1] = $11;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   661
				a = (char *)&data_dest.sin_addr;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   662
				a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   663
				$$ = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   664
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   665
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   666
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   667
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   668
form_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   669
	: N
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   670
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   671
			$$ = FORM_N;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   672
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   673
	| T
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   674
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   675
			$$ = FORM_T;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   676
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   677
	| C
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   678
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   679
			$$ = FORM_C;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   680
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   681
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   682
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   683
type_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   684
	: A
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   685
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   686
			cmd_type = TYPE_A;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   687
			cmd_form = FORM_N;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   688
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   689
	| A SP form_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   690
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   691
			cmd_type = TYPE_A;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   692
			cmd_form = $3;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   693
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   694
	| E
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   695
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   696
			cmd_type = TYPE_E;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   697
			cmd_form = FORM_N;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   698
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   699
	| E SP form_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   700
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   701
			cmd_type = TYPE_E;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   702
			cmd_form = $3;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   703
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   704
	| I
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   705
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   706
			cmd_type = TYPE_I;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   707
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   708
	| L
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   709
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   710
			cmd_type = TYPE_L;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   711
			cmd_bytesz = CHAR_BIT;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   712
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   713
	| L SP byte_size
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   714
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   715
			cmd_type = TYPE_L;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   716
			cmd_bytesz = $3;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   717
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   718
		/* this is for a bug in the BBN ftp */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   719
	| L byte_size
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   720
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   721
			cmd_type = TYPE_L;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   722
			cmd_bytesz = $2;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   723
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   724
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   725
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   726
struct_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   727
	: F
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   728
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   729
			$$ = STRU_F;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   730
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   731
	| R
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   732
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   733
			$$ = STRU_R;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   734
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   735
	| P
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   736
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   737
			$$ = STRU_P;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   738
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   739
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   740
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   741
mode_code
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   742
	: S
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   743
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   744
			$$ = MODE_S;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   745
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   746
	| B
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   747
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   748
			$$ = MODE_B;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   749
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   750
	| C
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   751
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   752
			$$ = MODE_C;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   753
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   754
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   755
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   756
pathname
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   757
	: pathstring
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   758
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   759
			/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   760
			 * Problem: this production is used for all pathname
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   761
			 * processing, but only gives a 550 error reply.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   762
			 * This is a valid reply in some cases but not in others.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   763
			 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   764
			if (logged_in && $1 && strchr($1, '~') != NULL) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   765
				glob_t gl;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   766
#ifdef __linux__
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   767
				/* see popen.c */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   768
				int flags = GLOB_NOCHECK;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   769
#else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   770
				int flags =
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   771
				 GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   772
#endif
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   773
				char *pptr = $1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   774
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   775
				/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   776
				 * glob() will only find a leading ~, but
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   777
				 * Netscape kindly puts a slash in front of
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   778
				 * it for publish URLs.  There needs to be
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   779
				 * a flag for glob() that expands tildes
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   780
				 * anywhere in the string.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   781
				 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   782
				if ((pptr[0] == '/') && (pptr[1] == '~'))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   783
					pptr++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   784
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   785
				memset(&gl, 0, sizeof(gl));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   786
				if (glob(pptr, flags, NULL, &gl) ||
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   787
				    gl.gl_pathc == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   788
					reply(550, "not found");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   789
					$$ = NULL;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   790
				} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   791
					$$ = strdup(gl.gl_pathv[0]);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   792
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   793
				globfree(&gl);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   794
				free($1);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   795
			} else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   796
				$$ = $1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   797
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   798
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   799
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   800
pathstring
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   801
	: STRING
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   802
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   803
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   804
octal_number
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   805
	: NUMBER
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   806
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   807
			int ret, dec, multby, digit;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   808
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   809
			/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   810
			 * Convert a number that was read as decimal number
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   811
			 * to what it would be if it had been read as octal.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   812
			 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   813
			dec = $1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   814
			multby = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   815
			ret = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   816
			while (dec) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   817
				digit = dec%10;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   818
				if (digit > 7) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   819
					ret = -1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   820
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   821
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   822
				ret += digit * multby;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   823
				multby *= 8;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   824
				dec /= 10;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   825
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   826
			$$ = ret;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   827
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   828
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   829
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   830
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   831
check_login
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   832
	: /* empty */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   833
		{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   834
			if (logged_in)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   835
				$$ = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   836
			else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   837
				reply(530, "Please login with USER and PASS.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   838
				$$ = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   839
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   840
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   841
	;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   842
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   843
%%
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   844
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   845
extern jmp_buf errcatch;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   846
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   847
#define	CMD	0	/* beginning of command */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   848
#define	ARGS	1	/* expect miscellaneous arguments */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   849
#define	STR1	2	/* expect SP followed by STRING */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   850
#define	STR2	3	/* expect STRING */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   851
#define	OSTR	4	/* optional SP then STRING */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   852
#define	ZSTR1	5	/* SP then optional STRING */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   853
#define	ZSTR2	6	/* optional STRING after SP */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   854
#define	SITECMD	7	/* SITE command */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   855
#define	NSTR	8	/* Number followed by a string */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   856
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   857
struct tab {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   858
	const char	*name;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   859
	short	token;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   860
	short	state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   861
	short	implemented;	/* 1 if command is implemented */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   862
	const char	*help;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   863
};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   864
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   865
struct tab cmdtab[] = {		/* In order defined in RFC 765 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   866
	{ "USER", USER, STR1, 1,	"<sp> username" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   867
	{ "PASS", PASS, ZSTR1, 1,	"<sp> password" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   868
	{ "ACCT", ACCT, STR1, 0,	"(specify account)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   869
	{ "SMNT", SMNT, ARGS, 0,	"(structure mount)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   870
	{ "REIN", REIN, ARGS, 0,	"(reinitialize server state)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   871
	{ "QUIT", QUIT, ARGS, 1,	"(terminate service)", },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   872
	{ "PORT", PORT, ARGS, 1,	"<sp> b0, b1, b2, b3, b4" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   873
	{ "PASV", PASV, ARGS, 1,	"(set server in passive mode)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   874
	{ "TYPE", TYPE, ARGS, 1,	"<sp> [ A | E | I | L ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   875
	{ "STRU", STRU, ARGS, 1,	"(specify file structure)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   876
	{ "MODE", MODE, ARGS, 1,	"(specify transfer mode)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   877
	{ "RETR", RETR, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   878
	{ "STOR", STOR, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   879
	{ "APPE", APPE, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   880
	{ "MLFL", MLFL, OSTR, 0,	"(mail file)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   881
	{ "MAIL", MAIL, OSTR, 0,	"(mail to user)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   882
	{ "MSND", MSND, OSTR, 0,	"(mail send to terminal)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   883
	{ "MSOM", MSOM, OSTR, 0,	"(mail send to terminal or mailbox)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   884
	{ "MSAM", MSAM, OSTR, 0,	"(mail send to terminal and mailbox)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   885
	{ "MRSQ", MRSQ, OSTR, 0,	"(mail recipient scheme question)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   886
	{ "MRCP", MRCP, STR1, 0,	"(mail recipient)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   887
	{ "ALLO", ALLO, ARGS, 1,	"allocate storage (vacuously)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   888
	{ "REST", REST, ARGS, 1,	"<sp> offset (restart command)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   889
	{ "RNFR", RNFR, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   890
	{ "RNTO", RNTO, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   891
	{ "ABOR", ABOR, ARGS, 1,	"(abort operation)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   892
	{ "DELE", DELE, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   893
	{ "CWD",  CWD,  OSTR, 1,	"[ <sp> directory-name ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   894
	{ "XCWD", CWD,	OSTR, 1,	"[ <sp> directory-name ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   895
	{ "LIST", LIST, OSTR, 1,	"[ <sp> path-name ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   896
	{ "NLST", NLST, OSTR, 1,	"[ <sp> path-name ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   897
	{ "SITE", SITE, SITECMD, 1,	"site-cmd [ <sp> arguments ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   898
	{ "SYST", SYST, ARGS, 1,	"(get type of operating system)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   899
	{ "STAT", STAT, OSTR, 1,	"[ <sp> path-name ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   900
	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   901
	{ "NOOP", NOOP, ARGS, 1,	"" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   902
	{ "MKD",  MKD,  STR1, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   903
	{ "XMKD", MKD,  STR1, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   904
	{ "RMD",  RMD,  STR1, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   905
	{ "XRMD", RMD,  STR1, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   906
	{ "PWD",  PWD,  ARGS, 1,	"(return current directory)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   907
	{ "XPWD", PWD,  ARGS, 1,	"(return current directory)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   908
	{ "CDUP", CDUP, ARGS, 1,	"(change to parent directory)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   909
	{ "XCUP", CDUP, ARGS, 1,	"(change to parent directory)" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   910
	{ "STOU", STOU, STR1, 1,	"<sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   911
	{ "SIZE", SIZE, OSTR, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   912
	{ "MDTM", MDTM, OSTR, 1,	"<sp> path-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   913
	{ NULL,   0,    0,    0,	0 }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   914
};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   915
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   916
struct tab sitetab[] = {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   917
	{ "UMASK", UMASK, ARGS, 1,	"[ <sp> umask ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   918
	{ "IDLE", IDLE, ARGS, 1,	"[ <sp> maximum-idle-time ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   919
	{ "CHMOD", CHMOD, NSTR, 1,	"<sp> mode <sp> file-name" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   920
	{ "HELP", HELP, OSTR, 1,	"[ <sp> <string> ]" },
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   921
	{ NULL,   0,    0,    0,	0 }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   922
};
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   923
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   924
static void	 help __P((struct tab *, char *));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   925
static struct tab *
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   926
		 lookup __P((struct tab *, char *));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   927
static void	 sizecmd __P((char *));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   928
static int	 yylex __P((void));
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   929
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   930
static struct tab *lookup(struct tab *p, char *cmd)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   931
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   932
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   933
	for (; p->name != NULL; p++)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   934
		if (strcmp(cmd, p->name) == 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   935
			return (p);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   936
	return (0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   937
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   938
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   939
#include <arpa/telnet.h>
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   940
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   941
/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   942
 * getline - a hacked up version of fgets to ignore TELNET escape codes.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   943
 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   944
char * ftpd_getline(char *s, int n, FILE *iop)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   945
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   946
	int c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   947
	register char *cs;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   948
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   949
	cs = s;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   950
/* tmpline may contain saved command from urgent mode interruption */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   951
	for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   952
		*cs++ = tmpline[c];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   953
		if (tmpline[c] == '\n') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   954
			*cs++ = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   955
			if (debug)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   956
				syslog(LOG_DEBUG, "command: %s", s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   957
			tmpline[0] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   958
			return(s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   959
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   960
		if (c == 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   961
			tmpline[0] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   962
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   963
	while ((c = getc(iop)) != EOF) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   964
		c &= 0377;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   965
		if (c == IAC) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   966
		    if ((c = getc(iop)) != EOF) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   967
			c &= 0377;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   968
			switch (c) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   969
			case WILL:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   970
			case WONT:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   971
				c = getc(iop);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   972
				printf("%c%c%c", IAC, DONT, 0377&c);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   973
				(void) fflush(stdout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   974
				continue;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   975
			case DO:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   976
			case DONT:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   977
				c = getc(iop);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   978
				printf("%c%c%c", IAC, WONT, 0377&c);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   979
				(void) fflush(stdout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   980
				continue;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   981
			case IAC:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   982
				break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   983
			default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   984
				continue;	/* ignore command */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   985
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   986
		    }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   987
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   988
		*cs++ = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   989
		if (--n <= 0 || c == '\n')
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   990
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   991
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   992
	if (c == EOF && cs == s)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   993
		return (NULL);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   994
	*cs++ = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   995
	if (debug) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   996
		if (!guest && strncasecmp("pass ", s, 5) == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   997
			/* Don't syslog passwords */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   998
			syslog(LOG_DEBUG, "command: %.5s ???", s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
   999
		} else {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1000
			register char *cp;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1001
			register int len;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1002
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1003
			/* Don't syslog trailing CR-LF */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1004
			len = strlen(s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1005
			cp = s + len - 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1006
			while (cp >= s && (*cp == '\n' || *cp == '\r')) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1007
				--cp;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1008
				--len;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1009
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1010
			syslog(LOG_DEBUG, "command: %.*s", len, s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1011
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1012
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1013
	return (s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1014
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1015
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1016
void toolong(int signo)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1017
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1018
	(void)signo;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1019
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1020
	reply(421,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1021
	    "Timeout (%d seconds): closing control connection.", timeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1022
	if (logging)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1023
		syslog(LOG_INFO, "User %s timed out after %d seconds",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1024
		    (pw ? pw -> pw_name : "unknown"), timeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1025
	dologout(1);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1026
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1027
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1028
static int yylex(void)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1029
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1030
	static int cpos, state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1031
	char *cp, *cp2;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1032
	struct tab *p;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1033
	int n, value;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1034
	char c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1035
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1036
	for (;;) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1037
		switch (state) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1038
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1039
		case CMD:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1040
			(void) signal(SIGALRM, toolong);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1041
			(void) alarm((unsigned) timeout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1042
			if (ftpd_getline(cbuf, sizeof(cbuf)-1, stdin)==NULL) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1043
				reply(221, "You could at least say goodbye.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1044
				dologout(0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1045
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1046
			(void) alarm(0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1047
			cp = strchr(cbuf, '\r');
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1048
			if (cp) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1049
				*cp++ = '\n';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1050
				*cp = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1051
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1052
#ifdef HASSETPROCTITLE
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1053
			if (strncasecmp(cbuf, "PASS", 4) != 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1054
				cp = strpbrk(cbuf, "\n");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1055
				if (cp) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1056
					c = *cp;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1057
					*cp = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1058
					setproctitle("%s: %s", proctitle, cbuf);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1059
					*cp = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1060
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1061
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1062
#endif /* HASSETPROCTITLE */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1063
			cp = strpbrk(cbuf, " \n");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1064
			if (cp)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1065
				cpos = cp - cbuf;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1066
			if (cpos == 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1067
				cpos = 4;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1068
			c = cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1069
			cbuf[cpos] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1070
			upper(cbuf);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1071
			p = lookup(cmdtab, cbuf);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1072
			cbuf[cpos] = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1073
			if (p != 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1074
				if (p->implemented == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1075
					nack(p->name);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1076
					longjmp(errcatch,0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1077
					/* NOTREACHED */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1078
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1079
				state = p->state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1080
				yylval.s = (char *)p->name;  /* XXX */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1081
				return (p->token);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1082
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1083
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1084
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1085
		case SITECMD:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1086
			if (cbuf[cpos] == ' ') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1087
				cpos++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1088
				return (SP);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1089
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1090
			cp = &cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1091
			cp2 = strpbrk(cp, " \n");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1092
			if (cp2)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1093
				cpos = cp2 - cbuf;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1094
			c = cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1095
			cbuf[cpos] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1096
			upper(cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1097
			p = lookup(sitetab, cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1098
			cbuf[cpos] = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1099
			if (p != 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1100
				if (p->implemented == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1101
					state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1102
					nack(p->name);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1103
					longjmp(errcatch,0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1104
					/* NOTREACHED */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1105
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1106
				state = p->state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1107
				yylval.s = (char *) p->name;  /* XXX */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1108
				return (p->token);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1109
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1110
			state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1111
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1112
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1113
		case OSTR:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1114
			if (cbuf[cpos] == '\n') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1115
				state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1116
				return (CRLF);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1117
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1118
			/* FALLTHROUGH */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1119
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1120
		case STR1:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1121
		case ZSTR1:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1122
		dostr1:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1123
			if (cbuf[cpos] == ' ') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1124
				cpos++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1125
				/* DOH!!! who wrote this?
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1126
				 * state = ++state; is undefined in C!
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1127
				 * state = state == OSTR ? STR2 : ++state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1128
				 * looks elegant but not correct, adding 'value'
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1129
				 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1130
				value = state == OSTR ? STR2 : ++state;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1131
				state = value;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1132
				return (SP);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1133
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1134
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1135
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1136
		case ZSTR2:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1137
			if (cbuf[cpos] == '\n') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1138
				state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1139
				return (CRLF);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1140
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1141
			/* FALLTHROUGH */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1142
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1143
		case STR2:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1144
			cp = &cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1145
			n = strlen(cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1146
			cpos += n - 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1147
			/*
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1148
			 * Make sure the string is nonempty and \n terminated.
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1149
			 */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1150
			if (n > 1 && cbuf[cpos] == '\n') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1151
				cbuf[cpos] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1152
				yylval.s = strdup(cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1153
				if (yylval.s == NULL)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1154
					fatal("Ran out of memory.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1155
				cbuf[cpos] = '\n';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1156
				state = ARGS;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1157
				return (STRING);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1158
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1159
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1160
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1161
		case NSTR:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1162
			if (cbuf[cpos] == ' ') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1163
				cpos++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1164
				return (SP);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1165
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1166
			if (isdigit(cbuf[cpos])) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1167
				cp = &cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1168
				while (isdigit(cbuf[++cpos]))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1169
					;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1170
				c = cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1171
				cbuf[cpos] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1172
				yylval.i = atoi(cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1173
				cbuf[cpos] = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1174
				state = STR1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1175
				return (NUMBER);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1176
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1177
			state = STR1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1178
			goto dostr1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1179
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1180
		case ARGS:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1181
			if (isdigit(cbuf[cpos])) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1182
				cp = &cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1183
				while (isdigit(cbuf[++cpos]))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1184
					;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1185
				c = cbuf[cpos];
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1186
				cbuf[cpos] = '\0';
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1187
				yylval.i = atoi(cp);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1188
				cbuf[cpos] = c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1189
				return (NUMBER);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1190
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1191
			switch (cbuf[cpos++]) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1192
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1193
			case '\n':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1194
				state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1195
				return (CRLF);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1196
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1197
			case ' ':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1198
				return (SP);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1199
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1200
			case ',':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1201
				return (COMMA);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1202
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1203
			case 'A':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1204
			case 'a':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1205
				return (A);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1206
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1207
			case 'B':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1208
			case 'b':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1209
				return (B);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1210
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1211
			case 'C':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1212
			case 'c':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1213
				return (C);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1214
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1215
			case 'E':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1216
			case 'e':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1217
				return (E);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1218
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1219
			case 'F':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1220
			case 'f':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1221
				return (F);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1222
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1223
			case 'I':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1224
			case 'i':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1225
				return (I);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1226
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1227
			case 'L':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1228
			case 'l':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1229
				return (L);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1230
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1231
			case 'N':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1232
			case 'n':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1233
				return (N);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1234
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1235
			case 'P':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1236
			case 'p':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1237
				return (P);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1238
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1239
			case 'R':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1240
			case 'r':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1241
				return (R);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1242
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1243
			case 'S':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1244
			case 's':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1245
				return (S);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1246
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1247
			case 'T':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1248
			case 't':
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1249
				return (T);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1250
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1251
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1252
			break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1253
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1254
		default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1255
			fatal("Unknown state in scanner.");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1256
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1257
		yyerror((char *) 0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1258
		state = CMD;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1259
		longjmp(errcatch,0);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1260
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1261
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1262
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1263
void upper(char *s)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1264
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1265
	while (*s != '\0') {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1266
		if (islower(*s))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1267
			*s = toupper(*s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1268
		s++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1269
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1270
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1271
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1272
static void help(struct tab *ctab, char *s)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1273
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1274
	struct tab *c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1275
	int width, NCMDS;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1276
	const char *type;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1277
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1278
	if (ctab == sitetab)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1279
		type = "SITE ";
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1280
	else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1281
		type = "";
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1282
	width = 0, NCMDS = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1283
	for (c = ctab; c->name != NULL; c++) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1284
		int len = strlen(c->name);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1285
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1286
		if (len > width)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1287
			width = len;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1288
		NCMDS++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1289
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1290
	width = (width + 8) &~ 7;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1291
	if (s == 0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1292
		int i, j, w;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1293
		int columns, lines;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1294
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1295
		lreply(214, "The following %scommands are recognized %s.",
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1296
		    type, "(* =>'s unimplemented)");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1297
		columns = 76 / width;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1298
		if (columns == 0)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1299
			columns = 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1300
		lines = (NCMDS + columns - 1) / columns;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1301
		for (i = 0; i < lines; i++) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1302
			printf("   ");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1303
			for (j = 0; j < columns; j++) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1304
				c = ctab + j * lines + i;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1305
				printf("%s%c", c->name,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1306
					c->implemented ? ' ' : '*');
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1307
				if (c + lines >= &ctab[NCMDS])
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1308
					break;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1309
				w = strlen(c->name) + 1;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1310
				while (w < width) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1311
					putchar(' ');
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1312
					w++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1313
				}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1314
			}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1315
			printf("\r\n");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1316
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1317
		(void) fflush(stdout);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1318
		reply(214, "Direct comments to ftp-bugs@%s.", hostname);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1319
		return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1320
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1321
	upper(s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1322
	c = lookup(ctab, s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1323
	if (c == (struct tab *)0) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1324
		reply(502, "Unknown command %s.", s);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1325
		return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1326
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1327
	if (c->implemented)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1328
		reply(214, "Syntax: %s%s %s", type, c->name, c->help);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1329
	else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1330
		reply(214, "%s%-*s\t%s; unimplemented.", type, width,
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1331
		    c->name, c->help);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1332
}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1333
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1334
static void sizecmd(char *filename)
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1335
{
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1336
	switch (type) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1337
	case TYPE_L:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1338
	case TYPE_I: {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1339
		struct stat stbuf;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1340
		if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1341
			reply(550, "%s: not a plain file.", filename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1342
		else
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1343
			reply(213, "%qu", (quad_t) stbuf.st_size);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1344
		break; }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1345
	case TYPE_A: {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1346
		FILE *fin;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1347
		int c;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1348
		off_t count;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1349
		struct stat stbuf;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1350
		fin = fopen(filename, "r");
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1351
		if (fin == NULL) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1352
			perror_reply(550, filename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1353
			return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1354
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1355
		if (fstat(fileno(fin), &stbuf) < 0 || !S_ISREG(stbuf.st_mode)) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1356
			reply(550, "%s: not a plain file.", filename);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1357
			(void) fclose(fin);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1358
			return;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1359
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1360
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1361
		count = 0;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1362
		while((c=getc(fin)) != EOF) {
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1363
			if (c == '\n')	/* will get expanded to \r\n */
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1364
				count++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1365
			count++;
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1366
		}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1367
		(void) fclose(fin);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1368
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1369
		reply(213, "%qd", (quad_t) count);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1370
		break; }
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1371
	default:
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1372
		reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1373
	}
c6b0df440bee Initial contribution of EPL licensed sources
ravikurupati
parents:
diff changeset
  1374
}