added a port of netkit ftp.exe

svn path=/trunk/; revision=12776
This commit is contained in:
Steven Edwards 2005-01-04 04:03:57 +00:00
parent 8c065412f4
commit 34bf6de206
15 changed files with 6783 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,185 @@
/*
* Copyright (c) 1985, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char sccsid[] = "@(#)cmdtab.c 5.9 (Berkeley) 3/21/89";
#endif /* not lint */
#include "ftp_var.h"
/*
* User FTP -- Command Tables.
*/
int setascii(), setbell(), setbinary(), setdebug(), setform();
int setglob(), sethash(), setmode(), setpeer(), setpassive(), setport();
int setprompt(), setstruct();
int settenex(), settrace(), settype(), setverbose();
int disconnect(), restart(), reget(), syst();
int cd(), lcd(), delete(), mdelete(), user();
int ls(), mls(), get(), mget(), help(), append(), put(), mput();
int quit(), renamefile(), status();
int quote(), rmthelp(), shell(), site();
int pwd(), makedir(), removedir(), setcr();
int account(), doproxy(), reset(), setcase(), setntrans(), setnmap();
int setsunique(), setrunique(), cdup(), macdef(), domacro();
int sizecmd(), modtime(), newer(), rmtstatus();
int do_chmod(), do_umask(), idle();
char accounthelp[] = "send account command to remote server";
char appendhelp[] = "append to a file";
char asciihelp[] = "set ascii transfer type";
char beephelp[] = "beep when command completed";
char binaryhelp[] = "set binary transfer type";
char casehelp[] = "toggle mget upper/lower case id mapping";
char cdhelp[] = "change remote working directory";
char cduphelp[] = "change remote working directory to parent directory";
char chmodhelp[] = "change file permissions of remote file";
char connecthelp[] = "connect to remote tftp";
char crhelp[] = "toggle carriage return stripping on ascii gets";
char deletehelp[] = "delete remote file";
char debughelp[] = "toggle/set debugging mode";
char dirhelp[] = "list contents of remote directory";
char disconhelp[] = "terminate ftp session";
char domachelp[] = "execute macro";
char formhelp[] = "set file transfer format";
char globhelp[] = "toggle metacharacter expansion of local file names";
char hashhelp[] = "toggle printing `#' for each buffer transferred";
char helphelp[] = "print local help information";
char idlehelp[] = "get (set) idle timer on remote side";
char lcdhelp[] = "change local working directory";
char lshelp[] = "list contents of remote directory";
char macdefhelp[] = "define a macro";
char mdeletehelp[] = "delete multiple files";
char mdirhelp[] = "list contents of multiple remote directories";
char mgethelp[] = "get multiple files";
char mkdirhelp[] = "make directory on the remote machine";
char mlshelp[] = "list contents of multiple remote directories";
char modtimehelp[] = "show last modification time of remote file";
char modehelp[] = "set file transfer mode";
char mputhelp[] = "send multiple files";
char newerhelp[] = "get file if remote file is newer than local file ";
char nlisthelp[] = "nlist contents of remote directory";
char nmaphelp[] = "set templates for default file name mapping";
char ntranshelp[] = "set translation table for default file name mapping";
char porthelp[] = "toggle use of PORT cmd for each data connection";
char prompthelp[] = "force interactive prompting on multiple commands";
char proxyhelp[] = "issue command on alternate connection";
char pwdhelp[] = "print working directory on remote machine";
char quithelp[] = "terminate ftp session and exit";
char quotehelp[] = "send arbitrary ftp command";
char receivehelp[] = "receive file";
char regethelp[] = "get file restarting at end of local file";
char remotehelp[] = "get help from remote server";
char renamehelp[] = "rename file";
char restarthelp[]= "restart file transfer at bytecount";
char rmdirhelp[] = "remove directory on the remote machine";
char rmtstatushelp[]="show status of remote machine";
char runiquehelp[] = "toggle store unique for local files";
char resethelp[] = "clear queued command replies";
char sendhelp[] = "send one file";
char passivehelp[] = "enter passive transfer mode";
char sitehelp[] = "send site specific command to remote server\n\t\tTry \"rhelp site\" or \"site help\" for more information";
char shellhelp[] = "escape to the shell";
char sizecmdhelp[] = "show size of remote file";
char statushelp[] = "show current status";
char structhelp[] = "set file transfer structure";
char suniquehelp[] = "toggle store unique on remote machine";
char systemhelp[] = "show remote system type";
char tenexhelp[] = "set tenex file transfer type";
char tracehelp[] = "toggle packet tracing";
char typehelp[] = "set file transfer type";
char umaskhelp[] = "get (set) umask on remote side";
char userhelp[] = "send new user information";
char verbosehelp[] = "toggle verbose mode";
struct cmd cmdtab[] = {
{ "!", shellhelp, 0, 0, 0, shell },
{ "$", domachelp, 1, 0, 0, domacro },
{ "account", accounthelp, 0, 1, 1, account},
{ "append", appendhelp, 1, 1, 1, put },
{ "ascii", asciihelp, 0, 1, 1, setascii },
{ "bell", beephelp, 0, 0, 0, setbell },
{ "binary", binaryhelp, 0, 1, 1, setbinary },
{ "bye", quithelp, 0, 0, 0, quit },
{ "case", casehelp, 0, 0, 1, setcase },
{ "cd", cdhelp, 0, 1, 1, cd },
{ "cdup", cduphelp, 0, 1, 1, cdup },
{ "chmod", chmodhelp, 0, 1, 1, do_chmod },
{ "close", disconhelp, 0, 1, 1, disconnect },
{ "cr", crhelp, 0, 0, 0, setcr },
{ "delete", deletehelp, 0, 1, 1, delete },
{ "debug", debughelp, 0, 0, 0, setdebug },
{ "dir", dirhelp, 1, 1, 1, ls },
{ "disconnect", disconhelp, 0, 1, 1, disconnect },
{ "form", formhelp, 0, 1, 1, setform },
{ "get", receivehelp, 1, 1, 1, get },
{ "glob", globhelp, 0, 0, 0, setglob },
{ "hash", hashhelp, 0, 0, 0, sethash },
{ "help", helphelp, 0, 0, 1, help },
{ "idle", idlehelp, 0, 1, 1, idle },
{ "image", binaryhelp, 0, 1, 1, setbinary },
{ "lcd", lcdhelp, 0, 0, 0, lcd },
{ "ls", lshelp, 1, 1, 1, ls },
{ "macdef", macdefhelp, 0, 0, 0, macdef },
{ "mdelete", mdeletehelp, 1, 1, 1, mdelete },
{ "mdir", mdirhelp, 1, 1, 1, mls },
{ "mget", mgethelp, 1, 1, 1, mget },
{ "mkdir", mkdirhelp, 0, 1, 1, makedir },
{ "mls", mlshelp, 1, 1, 1, mls },
{ "mode", modehelp, 0, 1, 1, setmode },
{ "modtime", modtimehelp, 0, 1, 1, modtime },
{ "mput", mputhelp, 1, 1, 1, mput },
{ "newer", newerhelp, 1, 1, 1, newer },
{ "nmap", nmaphelp, 0, 0, 1, setnmap },
{ "nlist", nlisthelp, 1, 1, 1, ls },
{ "ntrans", ntranshelp, 0, 0, 1, setntrans },
{ "open", connecthelp, 0, 0, 1, setpeer },
{ "passive",passivehelp,0, 0, 0, setpassive },
{ "prompt", prompthelp, 0, 0, 0, setprompt },
{ "proxy", proxyhelp, 0, 0, 1, doproxy },
{ "sendport", porthelp, 0, 0, 0, setport },
{ "put", sendhelp, 1, 1, 1, put },
{ "pwd", pwdhelp, 0, 1, 1, pwd },
{ "quit", quithelp, 0, 0, 0, quit },
{ "quote", quotehelp, 1, 1, 1, quote },
{ "recv", receivehelp, 1, 1, 1, get },
{ "reget", regethelp, 1, 1, 1, reget },
{ "rstatus", rmtstatushelp, 0, 1, 1, rmtstatus },
{ "rhelp", remotehelp, 0, 1, 1, rmthelp },
{ "rename", renamehelp, 0, 1, 1, renamefile },
{ "reset", resethelp, 0, 1, 1, reset },
{ "restart", restarthelp, 1, 1, 1, restart },
{ "rmdir", rmdirhelp, 0, 1, 1, removedir },
{ "runique", runiquehelp, 0, 0, 1, setrunique },
{ "send", sendhelp, 1, 1, 1, put },
{ "site", sitehelp, 0, 1, 1, site },
{ "size", sizecmdhelp, 1, 1, 1, sizecmd },
{ "status", statushelp, 0, 0, 1, status },
{ "struct", structhelp, 0, 1, 1, setstruct },
{ "system", systemhelp, 0, 1, 1, syst },
{ "sunique", suniquehelp, 0, 0, 1, setsunique },
{ "tenex", tenexhelp, 0, 1, 1, settenex },
{ "trace", tracehelp, 0, 0, 0, settrace },
{ "type", typehelp, 0, 1, 1, settype },
{ "user", userhelp, 0, 1, 1, user },
{ "umask", umaskhelp, 0, 1, 1, do_umask },
{ "verbose", verbosehelp, 0, 0, 0, setverbose },
{ "?", helphelp, 0, 0, 1, help },
{ 0 },
};
int NCMDS = (sizeof (cmdtab) / sizeof (cmdtab[0])) - 1;

View file

@ -0,0 +1,149 @@
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char sccsid[] = "@(#)domacro.c 1.6 (Berkeley) 2/28/89";
#endif /* not lint */
#include "ftp_var.h"
#include "prototypes.h"
#include <signal.h>
#include <stdio.h>
//#include <errno.h>
#include <ctype.h>
//#include <sys/ttychars.h>
void domacro(argc, argv)
int argc;
char *argv[];
{
register int i, j;
register char *cp1, *cp2;
int count = 2, loopflg = 0;
char line2[200];
extern char **glob(), *globerr;
struct cmd *getcmd(), *c;
extern struct cmd cmdtab[];
if (argc < 2) {
(void) strcat(line, " ");
printf("(macro name) ");
(void) fflush(stdout);
(void) gets(&line[strlen(line)]);
makeargv();
argc = margc;
argv = margv;
}
if (argc < 2) {
printf("Usage: %s macro_name.\n", argv[0]);
(void) fflush(stdout);
code = -1;
return;
}
for (i = 0; i < macnum; ++i) {
if (!strncmp(argv[1], macros[i].mac_name, 9)) {
break;
}
}
if (i == macnum) {
printf("'%s' macro not found.\n", argv[1]);
(void) fflush(stdout);
code = -1;
return;
}
(void) strcpy(line2, line);
TOP:
cp1 = macros[i].mac_start;
while (cp1 != macros[i].mac_end) {
while (isspace(*cp1)) {
cp1++;
}
cp2 = line;
while (*cp1 != '\0') {
switch(*cp1) {
case '\\':
*cp2++ = *++cp1;
break;
case '$':
if (isdigit(*(cp1+1))) {
j = 0;
while (isdigit(*++cp1)) {
j = 10*j + *cp1 - '0';
}
cp1--;
if (argc - 2 >= j) {
(void) strcpy(cp2, argv[j+1]);
cp2 += strlen(argv[j+1]);
}
break;
}
if (*(cp1+1) == 'i') {
loopflg = 1;
cp1++;
if (count < argc) {
(void) strcpy(cp2, argv[count]);
cp2 += strlen(argv[count]);
}
break;
}
/* intentional drop through */
default:
*cp2++ = *cp1;
break;
}
if (*cp1 != '\0') {
cp1++;
}
}
*cp2 = '\0';
makeargv();
c = getcmd(margv[0]);
if (c == (struct cmd *)-1) {
printf("?Ambiguous command\n");
code = -1;
}
else if (c == 0) {
printf("?Invalid command\n");
code = -1;
}
else if (c->c_conn && !connected) {
printf("Not connected.\n");
code = -1;
}
else {
if (verbose) {
printf("%s\n",line);
}
(*c->c_handler)(margc, margv);
if (bell && c->c_bell) {
(void) putchar('\007');
}
(void) strcpy(line, line2);
makeargv();
argc = margc;
argv = margv;
}
if (cp1 != macros[i].mac_end) {
cp1++;
}
(void) fflush(stdout);
}
if (loopflg && ++count < argc) {
goto TOP;
}
}

View file

@ -0,0 +1,300 @@
#include <stdio.h>
#include <time.h>
#include <winsock.h>
#include "prototypes.h"
#define MAX_ASCII 100
int checkRecv(SOCKET s);
int checkRecv(SOCKET s)
{
int testVal;
fd_set sSet;
struct timeval timeout;
timeout.tv_sec = 60;
FD_ZERO(&sSet);
FD_SET(s, &sSet);
testVal = select(0, &sSet, NULL, NULL, &timeout);
if (testVal == SOCKET_ERROR)
fprintf(stderr, "Socket Error");
return testVal;
}
void blkfree(char **av0)
{
register char **av = av0;
while (*av)
free(*av++);
}
char *glob(register char *v)
{
return NULL;
}
int sleep(int time)
{
return time;
}
int herror(char *string)
{
return 0;
}
#if 0
int gettimeofday(struct timeval *timenow,
struct timezone *zone)
{
time_t t;
t = clock();
timenow->tv_usec = t;
timenow->tv_sec = t / CLK_TCK;
return 0;
}
int fgetcSocket(int s)
{
int c;
char buffer[10];
// checkRecv(s);
c = recv(s, buffer, 1, 0);
#ifdef DEBUG_IN
printf("%c", buffer[0]);
#endif
if (c == INVALID_SOCKET)
return c;
if (c == 0)
return EOF;
return buffer[0];
}
#else
int fgetcSocket(int s)
{
static int index = 0;
static int total = 0;
static unsigned char buffer[4096];
if (index == total)
{
index = 0;
total = recv(s, buffer, sizeof(buffer), 0);
if (total == INVALID_SOCKET)
{
total = 0;
return ERROR;
}
if (total == 0)
return EOF;
}
return buffer[index++];
}
#endif
char *fprintfSocket(int s, char *format, ...)
{
va_list argptr;
char buffer[10009];
va_start(argptr, format);
vsprintf(buffer, format, argptr);
va_end(argptr);
send(s, buffer, strlen(buffer), 0);
return NULL;
}
char *fputsSocket(char *format, int s)
{
send(s, format, strlen(format), 0);
return NULL;
}
int fputcSocket(int s, char putChar)
{
char buffer[2];
buffer[0] = putChar;
buffer[1] = '\0';
if(SOCKET_ERROR==send(s, buffer, 1, 0)) {
int iret=WSAGetLastError ();
fprintf(stdout,"fputcSocket: %d\n",iret);
return 0;
}
else {
return putChar;
}
}
int fputSocket(int s, char *buffer, int len)
{
int iret;
while(len) {
if(SOCKET_ERROR==(iret=send(s, buffer, len, 0)))
{
iret=WSAGetLastError ();
fprintf(stdout,"fputcSocket: %d\n",iret);
return 0;
}
else {
return len-=iret;
}
}
return 0;
}
char *fgetsSocket(int s, char *string)
{
char buffer[2] = {0};
int i, count;
for (i = 0, count = 1; count != 0 && buffer[0] != '\n'; i++)
{
checkRecv(s);
count = recv(s, buffer, 1, 0);
if (count == SOCKET_ERROR)
{
printf("Error in fgetssocket");
return NULL;
}
if (count == 1)
{
string[i] = buffer[0];
if (i == MAX_ASCII - 3)
{
count = 0;
string[++i] = '\n';
string[++i] = '\0';
}
}
else
{
if (i == 0)
return NULL;
else
{
string[i] = '\n';
string[i + 1] = '\0'; // This is risky
return string;
}
}
}
string[i] = '\0';
#ifdef DEBUG_IN
printf("%s", string);
#endif
return string;
}
#if 0
char *getpass(const char *prompt)
{
static char string[64];
printf("%s", prompt);
gets(string);
return string;
}
#endif
char *getpass (const char * prompt)
{
static char input[256];
HANDLE in;
HANDLE err;
int count;
in = GetStdHandle (STD_INPUT_HANDLE);
err = GetStdHandle (STD_ERROR_HANDLE);
if (in == INVALID_HANDLE_VALUE || err == INVALID_HANDLE_VALUE)
return NULL;
if (WriteFile (err, prompt, strlen (prompt), &count, NULL))
{
int istty = (GetFileType (in) == FILE_TYPE_CHAR);
DWORD old_flags;
int rc;
if (istty)
{
if (GetConsoleMode (in, &old_flags))
SetConsoleMode (in, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
else
istty = 0;
}
/* Need to read line one byte at time to avoid blocking, if not a
tty, so always do it this way. */
count = 0;
while (1)
{
DWORD dummy;
char one_char;
rc = ReadFile (in, &one_char, 1, &dummy, NULL);
if (rc == 0)
break;
if (one_char == '\r')
{
/* CR is always followed by LF if reading from tty. */
if (istty)
continue;
else
break;
}
if (one_char == '\n')
break;
/* Silently truncate password string if overly long. */
if (count < sizeof (input) - 1)
input[count++] = one_char;
}
input[count] = '\0';
WriteFile (err, "\r\n", 2, &count, NULL);
if (istty)
SetConsoleMode (in, old_flags);
if (rc)
return input;
}
return NULL;
}
// Stubbed out here. Should be changed in Source code...
int access(const char *filename, int accessmethod)
{
return 0;
}

View file

@ -0,0 +1,10 @@
#define bcopy(s,d,l) memcpy((d),(s),(l))
#define bzero(cp,l) memset((cp),0,(l))
#define rindex strrchr
#define index strchr
#define getwd getcwd
#define strcasecmp strcmp
#define strncasecmp strnicmp

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,372 @@
# Microsoft Developer Studio Generated NMAKE File, Based on ftp.dsp
!IF "$(CFG)" == ""
CFG=ftp - Win32 Debug
!MESSAGE No configuration specified. Defaulting to ftp - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "ftp - Win32 Release" && "$(CFG)" != "ftp - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ftp.mak" CFG="ftp - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "ftp - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "ftp - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "ftp - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\ftp.exe"
!ELSE
ALL : "$(OUTDIR)\ftp.exe"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\cmds.obj"
-@erase "$(INTDIR)\cmdtab.obj"
-@erase "$(INTDIR)\domacro.obj"
-@erase "$(INTDIR)\fake.obj"
-@erase "$(INTDIR)\ftp.obj"
-@erase "$(INTDIR)\main.obj"
-@erase "$(INTDIR)\ruserpass.obj"
-@erase "$(INTDIR)\vc*.idb"
-@erase "$(OUTDIR)\ftp.exe"
-@erase "$(OUTDIR)\ftp.pch"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" \
/D "HAVE_TIMEVAL" /Fp"$(INTDIR)\ftp.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD\
/c
CPP_OBJS=.\Release/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ftp.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib wsock32.lib /nologo /subsystem:console /incremental:no\
/pdb:"$(OUTDIR)\ftp.pdb" /machine:I386 /out:"$(OUTDIR)\ftp.exe"
LINK32_OBJS= \
"$(INTDIR)\cmds.obj" \
"$(INTDIR)\cmdtab.obj" \
"$(INTDIR)\domacro.obj" \
"$(INTDIR)\fake.obj" \
"$(INTDIR)\ftp.obj" \
"$(INTDIR)\main.obj" \
"$(INTDIR)\ruserpass.obj"
"$(OUTDIR)\ftp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
TargetPath=.\Release\ftp.exe
InputPath=.\Release\ftp.exe
SOURCE=$(InputPath)
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\ftp.exe"
!ELSE
ALL : "$(OUTDIR)\ftp.exe"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\cmds.obj"
-@erase "$(INTDIR)\cmdtab.obj"
-@erase "$(INTDIR)\domacro.obj"
-@erase "$(INTDIR)\fake.obj"
-@erase "$(INTDIR)\ftp.obj"
-@erase "$(INTDIR)\main.obj"
-@erase "$(INTDIR)\ruserpass.obj"
-@erase "$(INTDIR)\vc*.idb"
-@erase "$(INTDIR)\vc*.pdb"
-@erase "$(OUTDIR)\ftp.exe"
-@erase "$(OUTDIR)\ftp.ilk"
-@erase "$(OUTDIR)\ftp.pdb"
-@erase "$(OUTDIR)\ftp.pch"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS"\
/Fp"$(INTDIR)\ftp.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
CPP_OBJS=.\Debug/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ftp.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib wsock32.lib /nologo /subsystem:console /incremental:yes\
/pdb:"$(OUTDIR)\ftp.pdb" /debug /machine:I386 /out:"$(OUTDIR)\ftp.exe"\
/pdbtype:sept
LINK32_OBJS= \
"$(INTDIR)\cmds.obj" \
"$(INTDIR)\cmdtab.obj" \
"$(INTDIR)\domacro.obj" \
"$(INTDIR)\fake.obj" \
"$(INTDIR)\ftp.obj" \
"$(INTDIR)\main.obj" \
"$(INTDIR)\ruserpass.obj"
"$(OUTDIR)\ftp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
TargetPath=.\Debug\ftp.exe
InputPath=.\Debug\ftp.exe
SOURCE=$(InputPath)
!ENDIF
!IF "$(CFG)" == "ftp - Win32 Release" || "$(CFG)" == "ftp - Win32 Debug"
SOURCE=.\cmds.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_CMDS_=\
".\fake.h"\
".\ftp_var.h"\
".\pathnames.h"\
".\prototypes.h"\
"$(INTDIR)\cmds.obj" : $(SOURCE) $(DEP_CPP_CMDS_) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_CMDS_=\
".\fake.h"\
".\ftp_var.h"\
".\pathnames.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\cmds.obj" : $(SOURCE) $(DEP_CPP_CMDS_) "$(INTDIR)"
!ENDIF
SOURCE=.\cmdtab.c
DEP_CPP_CMDTA=\
".\fake.h"\
".\ftp_var.h"\
"$(INTDIR)\cmdtab.obj" : $(SOURCE) $(DEP_CPP_CMDTA) "$(INTDIR)"
SOURCE=.\domacro.c
DEP_CPP_DOMAC=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\domacro.obj" : $(SOURCE) $(DEP_CPP_DOMAC) "$(INTDIR)"
SOURCE=.\fake.c
DEP_CPP_FAKE_=\
".\prototypes.h"\
"$(INTDIR)\fake.obj" : $(SOURCE) $(DEP_CPP_FAKE_) "$(INTDIR)"
SOURCE=.\ftp.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_FTP_C=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\ftp.obj" : $(SOURCE) $(DEP_CPP_FTP_C) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_FTP_C=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\ftp.obj" : $(SOURCE) $(DEP_CPP_FTP_C) "$(INTDIR)"
!ENDIF
SOURCE=.\main.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_MAIN_=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\main.obj" : $(SOURCE) $(DEP_CPP_MAIN_) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_MAIN_=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\main.obj" : $(SOURCE) $(DEP_CPP_MAIN_) "$(INTDIR)"
!ENDIF
SOURCE=.\ruserpass.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_RUSER=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\ruserpass.obj" : $(SOURCE) $(DEP_CPP_RUSER) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_RUSER=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\ruserpass.obj" : $(SOURCE) $(DEP_CPP_RUSER) "$(INTDIR)"
!ENDIF
!ENDIF

View file

@ -0,0 +1,400 @@
# Microsoft Developer Studio Generated NMAKE File, Based on ftp.dsp
!IF "$(CFG)" == ""
CFG=ftp - Win32 Debug
!MESSAGE No configuration specified. Defaulting to ftp - Win32 Debug.
!ENDIF
!IF "$(CFG)" != "ftp - Win32 Release" && "$(CFG)" != "ftp - Win32 Debug"
!MESSAGE Invalid configuration "$(CFG)" specified.
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ftp.mak" CFG="ftp - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "ftp - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "ftp - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
!ERROR An invalid configuration is specified.
!ENDIF
!IF "$(OS)" == "Windows_NT"
NULL=
!ELSE
NULL=nul
!ENDIF
!IF "$(CFG)" == "ftp - Win32 Release"
OUTDIR=.\Release
INTDIR=.\Release
# Begin Custom Macros
OutDir=.\Release
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\ftp.exe" "\emacs-19.34\bin\ftp.exe"
!ELSE
ALL : "$(OUTDIR)\ftp.exe" "\emacs-19.34\bin\ftp.exe"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\cmds.obj"
-@erase "$(INTDIR)\cmdtab.obj"
-@erase "$(INTDIR)\domacro.obj"
-@erase "$(INTDIR)\fake.obj"
-@erase "$(INTDIR)\ftp.obj"
-@erase "$(INTDIR)\main.obj"
-@erase "$(INTDIR)\ruserpass.obj"
-@erase "$(INTDIR)\vc50.idb"
-@erase "$(OUTDIR)\ftp.exe"
-@erase "\emacs-19.34\bin\ftp.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /ML /W3 /GX /O2 /I "C:\emacs-19.34\nt\inc" /I\
"C:\emacs-19.34\src" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /D\
"HAVE_TIMEVAL" /Fp"$(INTDIR)\ftp.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD\
/c
CPP_OBJS=.\Release/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ftp.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib /nologo /subsystem:console /incremental:no\
/pdb:"$(OUTDIR)\ftp.pdb" /machine:I386 /out:"$(OUTDIR)\ftp.exe"
LINK32_OBJS= \
"$(INTDIR)\cmds.obj" \
"$(INTDIR)\cmdtab.obj" \
"$(INTDIR)\domacro.obj" \
"$(INTDIR)\fake.obj" \
"$(INTDIR)\ftp.obj" \
"$(INTDIR)\main.obj" \
"$(INTDIR)\ruserpass.obj" \
"d:\Program Files\DevStudio\VC\lib\WSOCK32.LIB"
"$(OUTDIR)\ftp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
TargetPath=.\Release\ftp.exe
InputPath=.\Release\ftp.exe
SOURCE=$(InputPath)
"\emacs-19.34\bin\ftp.exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# copy $(TargetPath) \emacs-19.34\bin
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
OUTDIR=.\Debug
INTDIR=.\Debug
# Begin Custom Macros
OutDir=.\Debug
# End Custom Macros
!IF "$(RECURSE)" == "0"
ALL : "$(OUTDIR)\ftp.exe" "\emacs-19.34\bin\ftp.exe"
!ELSE
ALL : "$(OUTDIR)\ftp.exe" "\emacs-19.34\bin\ftp.exe"
!ENDIF
CLEAN :
-@erase "$(INTDIR)\cmds.obj"
-@erase "$(INTDIR)\cmdtab.obj"
-@erase "$(INTDIR)\domacro.obj"
-@erase "$(INTDIR)\fake.obj"
-@erase "$(INTDIR)\ftp.obj"
-@erase "$(INTDIR)\main.obj"
-@erase "$(INTDIR)\ruserpass.obj"
-@erase "$(INTDIR)\vc50.idb"
-@erase "$(INTDIR)\vc50.pdb"
-@erase "$(OUTDIR)\ftp.exe"
-@erase "$(OUTDIR)\ftp.ilk"
-@erase "$(OUTDIR)\ftp.pdb"
-@erase "\emacs-19.34\bin\ftp.exe"
"$(OUTDIR)" :
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP=cl.exe
CPP_PROJ=/nologo /MLd /W3 /Gm /GX /Zi /Od /I "C:\emacs-19.34\nt\inc" /I\
"C:\emacs-19.34\src" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS"\
/Fp"$(INTDIR)\ftp.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
CPP_OBJS=.\Debug/
CPP_SBRS=.
.c{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_OBJS)}.obj::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.c{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cpp{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
.cxx{$(CPP_SBRS)}.sbr::
$(CPP) @<<
$(CPP_PROJ) $<
<<
RSC=rc.exe
BSC32=bscmake.exe
BSC32_FLAGS=/nologo /o"$(OUTDIR)\ftp.bsc"
BSC32_SBRS= \
LINK32=link.exe
LINK32_FLAGS=kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib\
advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib\
odbccp32.lib /nologo /subsystem:console /incremental:yes\
/pdb:"$(OUTDIR)\ftp.pdb" /debug /machine:I386 /out:"$(OUTDIR)\ftp.exe"\
/pdbtype:sept
LINK32_OBJS= \
"$(INTDIR)\cmds.obj" \
"$(INTDIR)\cmdtab.obj" \
"$(INTDIR)\domacro.obj" \
"$(INTDIR)\fake.obj" \
"$(INTDIR)\ftp.obj" \
"$(INTDIR)\main.obj" \
"$(INTDIR)\ruserpass.obj" \
"d:\Program Files\DevStudio\VC\lib\WSOCK32.LIB"
"$(OUTDIR)\ftp.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) @<<
$(LINK32_FLAGS) $(LINK32_OBJS)
<<
TargetPath=.\Debug\ftp.exe
InputPath=.\Debug\ftp.exe
SOURCE=$(InputPath)
"\emacs-19.34\bin\ftp.exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
# copy $(TargetPath) \emacs-19.34\bin
!ENDIF
!IF "$(CFG)" == "ftp - Win32 Release" || "$(CFG)" == "ftp - Win32 Debug"
SOURCE=.\cmds.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_CMDS_=\
".\fake.h"\
".\ftp_var.h"\
".\pathnames.h"\
".\prototypes.h"\
"$(INTDIR)\cmds.obj" : $(SOURCE) $(DEP_CPP_CMDS_) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_CMDS_=\
"..\..\..\emacs-19.34\nt\inc\netdb.h"\
"..\..\..\emacs-19.34\nt\inc\netinet\in.h"\
"..\..\..\emacs-19.34\nt\inc\sys\socket.h"\
"..\..\..\emacs-19.34\src\nt.h"\
".\fake.h"\
".\ftp_var.h"\
".\pathnames.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\cmds.obj" : $(SOURCE) $(DEP_CPP_CMDS_) "$(INTDIR)"
!ENDIF
SOURCE=.\cmdtab.c
DEP_CPP_CMDTA=\
".\fake.h"\
".\ftp_var.h"\
"$(INTDIR)\cmdtab.obj" : $(SOURCE) $(DEP_CPP_CMDTA) "$(INTDIR)"
SOURCE=.\domacro.c
DEP_CPP_DOMAC=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\domacro.obj" : $(SOURCE) $(DEP_CPP_DOMAC) "$(INTDIR)"
SOURCE=.\fake.c
DEP_CPP_FAKE_=\
".\prototypes.h"\
"$(INTDIR)\fake.obj" : $(SOURCE) $(DEP_CPP_FAKE_) "$(INTDIR)"
SOURCE=.\ftp.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_FTP_C=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\ftp.obj" : $(SOURCE) $(DEP_CPP_FTP_C) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_FTP_C=\
"..\..\..\emacs-19.34\nt\inc\netdb.h"\
"..\..\..\emacs-19.34\nt\inc\netinet\in.h"\
"..\..\..\emacs-19.34\nt\inc\pwd.h"\
"..\..\..\emacs-19.34\nt\inc\sys\file.h"\
"..\..\..\emacs-19.34\nt\inc\sys\ioctl.h"\
"..\..\..\emacs-19.34\nt\inc\sys\param.h"\
"..\..\..\emacs-19.34\nt\inc\sys\socket.h"\
"..\..\..\emacs-19.34\nt\inc\sys\time.h"\
"..\..\..\emacs-19.34\src\nt.h"\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\ftp.obj" : $(SOURCE) $(DEP_CPP_FTP_C) "$(INTDIR)"
!ENDIF
SOURCE=.\main.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_MAIN_=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\main.obj" : $(SOURCE) $(DEP_CPP_MAIN_) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_MAIN_=\
"..\..\..\emacs-19.34\nt\inc\netdb.h"\
"..\..\..\emacs-19.34\nt\inc\pwd.h"\
"..\..\..\emacs-19.34\nt\inc\sys\ioctl.h"\
"..\..\..\emacs-19.34\nt\inc\sys\socket.h"\
"..\..\..\emacs-19.34\src\nt.h"\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\main.obj" : $(SOURCE) $(DEP_CPP_MAIN_) "$(INTDIR)"
!ENDIF
SOURCE=.\ruserpass.c
!IF "$(CFG)" == "ftp - Win32 Release"
DEP_CPP_RUSER=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
"$(INTDIR)\ruserpass.obj" : $(SOURCE) $(DEP_CPP_RUSER) "$(INTDIR)"
!ELSEIF "$(CFG)" == "ftp - Win32 Debug"
DEP_CPP_RUSER=\
".\fake.h"\
".\ftp_var.h"\
".\prototypes.h"\
{$(INCLUDE)}"sys\stat.h"\
{$(INCLUDE)}"sys\types.h"\
"$(INTDIR)\ruserpass.obj" : $(SOURCE) $(DEP_CPP_RUSER) "$(INTDIR)"
!ENDIF
!ENDIF

View file

@ -0,0 +1,6 @@
/* $Id: route.rc 11816 2004-11-26 06:51:47Z arty $ */
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS TCP/IPv4 FTP Client\0"
#define REACTOS_STR_INTERNAL_NAME "ftp\0"
#define REACTOS_STR_ORIGINAL_FILENAME "ftp.exe\0"
#include <reactos/version.rc>

View file

@ -0,0 +1,181 @@
#include "fake.h"
#include <winsock.h>
#include <setjmp.h>
//typedef void (*Sig_t)(int);
int fgetcSocket(int s);
char *fputsSocket(char *format, int s);
char *fprintfSocket(int s, char *format, ...);
int fputcSocket(int s, char putChar);
int fputSocket(int s, char *putChar, int len);
char *fgetsSocket(int s, char *string);
/* The following defines are from ftp.h and telnet.h from bsd.h */
/* All relevent copyrights below apply. */
#define IAC 255
#define DONT 254
#define DO 253
#define WONT 252
#define WILL 251
#define SB 250
#define GA 249
#define EL 248
#define EC 247
#define AYT 246
#define AO 245
#define IP 244
#define BREAK 243
#define DM 242
#define NOP 241
#define SE 240
#define EOR 239
#define ABORT 238
#define SUSP 237
#define xEOF 236
#define MAXPATHLEN 255
#define TYPE_A 'A'
#define TYPE_I 'I'
#define TYPE_E 'E'
#define TYPE_L 'L'
#define PRELIM 1
#define COMPLETE 2
#define CONTINUE 3
#define TRANSIENT 4
#define MODE_S 1
#define MODE_B 2
#define MODE_C 3
#define STRU_F 1
#define STRU_R 2
#define STRU_P 3
#define SIGQUIT 1
#define SIGPIPE 2
#define SIGALRM 3
#define FORM_N 1
#define FORM_T 2
#define FORM_C 3
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#)ftp_var.h 5.5 (Berkeley) 6/29/88
*/
/*
* FTP global variables.
*/
/*
* Options and other state info.
*/
extern int trace; /* trace packets exchanged */
extern int hash; /* print # for each buffer transferred */
extern int sendport; /* use PORT cmd for each data connection */
extern int verbose; /* print messages coming back from server */
extern int connected; /* connected to server */
extern int fromatty; /* input is from a terminal */
extern int interactive; /* interactively prompt on m* cmds */
extern int debug; /* debugging level */
extern int bell; /* ring bell on cmd completion */
extern int doglob; /* glob local file names */
extern int proxy; /* proxy server connection active */
extern int proxflag; /* proxy connection exists */
extern int sunique; /* store files on server with unique name */
extern int runique; /* store local files with unique name */
extern int mcase; /* map upper to lower case for mget names */
extern int ntflag; /* use ntin ntout tables for name translation */
extern int mapflag; /* use mapin mapout templates on file names */
extern int code; /* return/reply code for ftp command */
extern int crflag; /* if 1, strip car. rets. on ascii gets */
extern char pasv[64]; /* passive port for proxy data connection */
extern int passivemode; /* passive mode enabled */
extern char *altarg; /* argv[1] with no shell-like preprocessing */
extern char ntin[17]; /* input translation table */
extern char ntout[17]; /* output translation table */
extern char mapin[MAXPATHLEN]; /* input map template */
extern char mapout[MAXPATHLEN]; /* output map template */
extern char typename[32]; /* name of file transfer type */
extern int type; /* file transfer type */
extern char structname[32]; /* name of file transfer structure */
extern int stru; /* file transfer structure */
extern char formname[32]; /* name of file transfer format */
extern int form; /* file transfer format */
extern char modename[32]; /* name of file transfer mode */
extern int mode; /* file transfer mode */
extern char bytename[32]; /* local byte size in ascii */
extern int bytesize; /* local byte size in binary */
extern jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
extern char line[200]; /* input line buffer */
extern char *stringbase; /* current scan point in line buffer */
extern char argbuf[200]; /* argument storage buffer */
extern char *argbase; /* current storage point in arg buffer */
extern int margc; /* count of arguments on input line */
extern char *margv[20]; /* args parsed from input line */
extern int cpend; /* flag: if != 0, then pending server reply */
extern int mflag; /* flag: if != 0, then active multi command */
extern int options; /* used during socket creation */
/*
* Format of command table.
*/
struct cmd {
char *c_name; /* name of command */
char *c_help; /* help string */
char c_bell; /* give bell when command completes */
char c_conn; /* must be connected to use command */
char c_proxy; /* proxy server may execute */
int (*c_handler)(); /* function to call */
};
struct macel {
char mac_name[9]; /* macro name */
char *mac_start; /* start of macro in macbuf */
char *mac_end; /* end of macro in macbuf */
};
int macnum; /* number of defined macros */
struct macel macros[16];
char macbuf[4096];
extern char *tail();
extern char *remglob();
extern int errno;
extern char *mktemp();
#if defined(__ANSI__) || defined(sparc)
typedef void sig_t;
#else
typedef int sig_t;
#endif
typedef int uid_t;
int herror(char *s);

View file

@ -0,0 +1,602 @@
/*
* Copyright (c) 1985, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1985, 1989 Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)main.c based on 5.13 (Berkeley) 3/14/89";
#endif /* not lint */
/*
* FTP User Program -- Command Interface.
*/
#if !defined(WIN32)
#include <netdb.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/ftp.h>
#include <errno.h>
#include <pwd.h>
#endif
#include "ftp_var.h"
#include "prototypes.h"
#include <sys/types.h>
#include <io.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#if defined(sun) && !defined(FD_SET)
typedef int uid_t;
#endif
uid_t getuid();
void intr();
void lostpeer();
char *getlogin();
short portnum;
char home[128];
char *globerr;
int autologin;
/* Lot's of options... */
/*
* Options and other state info.
*/
int trace; /* trace packets exchanged */
int hash; /* print # for each buffer transferred */
int sendport; /* use PORT cmd for each data connection */
int verbose; /* print messages coming back from server */
int connected; /* connected to server */
int fromatty; /* input is from a terminal */
int interactive; /* interactively prompt on m* cmds */
int debug; /* debugging level */
int bell; /* ring bell on cmd completion */
int doglob; /* glob local file names */
int proxy; /* proxy server connection active */
int passivemode;
int proxflag; /* proxy connection exists */
int sunique; /* store files on server with unique name */
int runique; /* store local files with unique name */
int mcase; /* map upper to lower case for mget names */
int ntflag; /* use ntin ntout tables for name translation */
int mapflag; /* use mapin mapout templates on file names */
int code; /* return/reply code for ftp command */
int crflag; /* if 1, strip car. rets. on ascii gets */
char pasv[64]; /* passive port for proxy data connection */
char *altarg; /* argv[1] with no shell-like preprocessing */
char ntin[17]; /* input translation table */
char ntout[17]; /* output translation table */
// #include <sys/param.h>
char mapin[MAXPATHLEN]; /* input map template */
char mapout[MAXPATHLEN]; /* output map template */
char typename[32]; /* name of file transfer type */
int type; /* file transfer type */
char structname[32]; /* name of file transfer structure */
int stru; /* file transfer structure */
char formname[32]; /* name of file transfer format */
int form; /* file transfer format */
char modename[32]; /* name of file transfer mode */
int mode; /* file transfer mode */
char bytename[32]; /* local byte size in ascii */
int bytesize; /* local byte size in binary */
jmp_buf toplevel; /* non-local goto stuff for cmd scanner */
char line[200]; /* input line buffer */
char *stringbase; /* current scan point in line buffer */
char argbuf[200]; /* argument storage buffer */
char *argbase; /* current storage point in arg buffer */
int margc; /* count of arguments on input line */
char *margv[20]; /* args parsed from input line */
int cpend; /* flag: if != 0, then pending server reply */
int mflag; /* flag: if != 0, then active multi command */
int options; /* used during socket creation */
int main(int argc, char *argv[])
{
register char *cp;
int top;
struct passwd *pw = NULL;
#if 0
char homedir[MAXPATHLEN];
#endif
int err;
WORD wVerReq;
WSADATA WSAData;
struct servent *sp; /* service spec for tcp/ftp */
/* Disable output buffering, for the benefit of Emacs. */
//setbuf(stdout, NULL);
_fmode = O_BINARY; // This causes an error somewhere.
wVerReq = MAKEWORD(1,1);
err = WSAStartup(wVerReq, &WSAData);
if (err != 0)
{
fprintf(stderr, "Could not initialize Windows socket interface.");
exit(1);
}
sp = getservbyname("ftp", "tcp");
if (sp == 0) {
fprintf(stderr, "ftp: ftp/tcp: unknown service\n");
exit(1);
}
portnum = sp->s_port;
doglob = 1;
interactive = 1;
autologin = 1;
argc--, argv++;
while (argc > 0 && **argv == '-') {
for (cp = *argv + 1; *cp; cp++)
switch (*cp) {
case 'd':
options |= SO_DEBUG;
debug++;
break;
case 'v':
verbose++;
break;
case 't':
trace++;
break;
case 'i':
interactive = 0;
break;
case 'n':
autologin = 0;
break;
case 'g':
doglob = 0;
break;
default:
fprintf(stdout,
"ftp: %c: unknown option\n", *cp);
exit(1);
}
argc--, argv++;
}
// fromatty = isatty(fileno(stdin));
fromatty = 1; // Strengthen this test
/*
* Set up defaults for FTP.
*/
(void) strcpy(typename, "ascii"), type = TYPE_A;
(void) strcpy(formname, "non-print"), form = FORM_N;
(void) strcpy(modename, "stream"), mode = MODE_S;
(void) strcpy(structname, "file"), stru = STRU_F;
(void) strcpy(bytename, "8"), bytesize = 8;
if (fromatty)
verbose++;
cpend = 0; /* no pending replies */
proxy = 0; /* proxy not active */
passivemode = 1; /* passive mode *is* active */
crflag = 1; /* strip c.r. on ascii gets */
/*
* Set up the home directory in case we're globbing.
*/
#if 0
cp = getlogin();
if (cp != NULL) {
pw = getpwnam(cp);
}
if (pw == NULL)
pw = getpwuid(getuid());
if (pw != NULL) {
home = homedir;
(void) strcpy(home, pw->pw_dir);
}
#endif
strcpy(home, "C:/");
if (argc > 0) {
if (setjmp(toplevel))
exit(0);
// (void) signal(SIGINT, intr);
// (void) signal(SIGPIPE, lostpeer);
setpeer(argc + 1, argv - 1);
}
top = setjmp(toplevel) == 0;
if (top) {
// (void) signal(SIGINT, intr);
// (void) signal(SIGPIPE, lostpeer);
}
for (;;) {
cmdscanner(top);
top = 1;
}
}
void
intr()
{
longjmp(toplevel, 1);
}
void lostpeer(void)
{
extern int cout;
extern int data;
if (connected) {
if (cout != (int) NULL) {
closesocket(cout);
cout = (int) NULL;
}
if (data >= 0) {
(void) shutdown(data, 1+1);
(void) close(data);
data = -1;
}
connected = 0;
}
pswitch(1);
if (connected) {
if (cout != (int)NULL) {
closesocket(cout);
cout = (int) NULL;
}
connected = 0;
}
proxflag = 0;
pswitch(0);
}
/*char *
tail(filename)
char *filename;
{
register char *s;
while (*filename) {
s = rindex(filename, '/');
if (s == NULL)
break;
if (s[1])
return (s + 1);
*s = '\0';
}
return (filename);
}
*/
/*
* Command parser.
*/
void cmdscanner(top)
int top;
{
register struct cmd *c;
struct cmd *getcmd();
extern int help();
if (!top)
(void) putchar('\n');
for (;;) {
(void) fflush(stdout);
if (fromatty) {
printf("ftp> ");
(void) fflush(stdout);
}
if (gets(line) == 0) {
if (feof(stdin) || ferror(stdin))
quit();
break;
}
if (line[0] == 0)
break;
makeargv();
if (margc == 0) {
continue;
}
c = getcmd(margv[0]);
if (c == (struct cmd *)-1) {
printf("?Ambiguous command\n");
continue;
}
if (c == 0) {
printf("?Invalid command\n");
continue;
}
if (c->c_conn && !connected) {
printf ("Not connected.\n");
continue;
}
(*c->c_handler)(margc, margv);
if (bell && c->c_bell)
(void) putchar('\007');
if (c->c_handler != help)
break;
}
(void) fflush(stdout);
// (void) signal(SIGINT, intr);
// (void) signal(SIGPIPE, lostpeer);
}
struct cmd *
getcmd(name)
register char *name;
{
extern struct cmd cmdtab[];
register char *p, *q;
register struct cmd *c, *found;
register int nmatches, longest;
longest = 0;
nmatches = 0;
found = 0;
for (c = cmdtab; p = c->c_name; c++) {
for (q = name; *q == *p++; q++)
if (*q == 0) /* exact match? */
return (c);
if (!*q) { /* the name was a prefix */
if (q - name > longest) {
longest = q - name;
nmatches = 1;
found = c;
} else if (q - name == longest)
nmatches++;
}
}
if (nmatches > 1)
return ((struct cmd *)-1);
return (found);
}
/*
* Slice a string up into argc/argv.
*/
int slrflag;
void makeargv()
{
char **argp;
char *slurpstring();
margc = 0;
argp = margv;
stringbase = line; /* scan from first of buffer */
argbase = argbuf; /* store from first of buffer */
slrflag = 0;
while (*argp++ = slurpstring())
margc++;
}
/*
* Parse string into argbuf;
* implemented with FSM to
* handle quoting and strings
*/
char *
slurpstring()
{
int got_one = 0;
register char *sb = stringbase;
register char *ap = argbase;
char *tmp = argbase; /* will return this if token found */
if (*sb == '!' || *sb == '$') { /* recognize ! as a token for shell */
switch (slrflag) { /* and $ as token for macro invoke */
case 0:
slrflag++;
stringbase++;
return ((*sb == '!') ? "!" : "$");
/* NOTREACHED */
case 1:
slrflag++;
altarg = stringbase;
break;
default:
break;
}
}
S0:
switch (*sb) {
case '\0':
goto OUT1;
case ' ':
case '\t':
sb++; goto S0;
default:
switch (slrflag) {
case 0:
slrflag++;
break;
case 1:
slrflag++;
altarg = sb;
break;
default:
break;
}
goto S1;
}
S1:
switch (*sb) {
case ' ':
case '\t':
case '\0':
goto OUT1; /* end of token */
case '\\':
sb++; goto S2; /* slurp next character */
case '"':
sb++; goto S3; /* slurp quoted string */
default:
*ap++ = *sb++; /* add character to token */
got_one = 1;
goto S1;
}
S2:
switch (*sb) {
case '\0':
goto OUT1;
default:
*ap++ = *sb++;
got_one = 1;
goto S1;
}
S3:
switch (*sb) {
case '\0':
goto OUT1;
case '"':
sb++; goto S1;
default:
*ap++ = *sb++;
got_one = 1;
goto S3;
}
OUT1:
if (got_one)
*ap++ = '\0';
argbase = ap; /* update storage pointer */
stringbase = sb; /* update scan pointer */
if (got_one) {
return(tmp);
}
switch (slrflag) {
case 0:
slrflag++;
break;
case 1:
slrflag++;
altarg = (char *) 0;
break;
default:
break;
}
return((char *)0);
}
#define HELPINDENT (sizeof ("directory"))
/*
* Help command.
* Call each command handler with argc == 0 and argv[0] == name.
*/
int help(argc, argv)
int argc;
char *argv[];
{
extern struct cmd cmdtab[];
register struct cmd *c;
if (argc == 1) {
register int i, j, w, k;
int columns, width = 0, lines;
extern int NCMDS;
printf("Commands may be abbreviated. Commands are:\n\n");
for (c = cmdtab; c < &cmdtab[NCMDS]; c++) {
int len = strlen(c->c_name);
if (len > width)
width = len;
}
width = (width + 8) &~ 7;
columns = 80 / width;
if (columns == 0)
columns = 1;
lines = (NCMDS + columns - 1) / columns;
for (i = 0; i < lines; i++) {
for (j = 0; j < columns; j++) {
c = cmdtab + j * lines + i;
if (c->c_name && (!proxy || c->c_proxy)) {
printf("%s", c->c_name);
}
else if (c->c_name) {
for (k=0; k < (int) strlen(c->c_name); k++) {
(void) putchar(' ');
}
}
if (c + lines >= &cmdtab[NCMDS]) {
printf("\n");
break;
}
w = strlen(c->c_name);
while (w < width) {
w = (w + 8) &~ 7;
(void) putchar('\t');
}
}
}
(void) fflush(stdout);
return 0;
}
while (--argc > 0) {
register char *arg;
arg = *++argv;
c = getcmd(arg);
if (c == (struct cmd *)-1)
printf("?Ambiguous help command %s\n", arg);
else if (c == (struct cmd *)0)
printf("?Invalid help command %s\n", arg);
else
printf("%-*s\t%s\n", HELPINDENT,
c->c_name, c->c_help);
}
(void) fflush(stdout);
return 0;
}

View file

@ -0,0 +1,26 @@
PATH_TO_TOP = ../../../..
TARGET_TYPE = program
TARGET_APPTYPE = console
TARGET_NAME = ftp
TARGET_INSTALLDIR = system32
TARGET_SDKLIBS = ws2_32.a iphlpapi.a ntdll.a
TARGET_OBJECTS = \
cmds.o \
cmdtab.o \
domacro.o \
fake.o \
ftp.o \
main.o \
ruserpass.o
TARGET_GCCLIBS =
include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* %W% (Berkeley) %G%
*/
#define _PATH_TMP "/tmp/ftpXXXXXX"
#define _PATH_BSHELL "/bin/sh"

View file

@ -0,0 +1,79 @@
int getreply(int expecteof);
int ruserpass(char *host, char **aname, char **apass, char **aacct);
char *getpass(const char *prompt);
void makeargv(void);
void domacro(int argc, char *argv[]);
void proxtrans(char *cmd, char *local, char *remote);
int null(void);
int initconn(void);
void disconnect(void);
void ptransfer(char *direction, long bytes, struct timeval *t0, struct timeval *t1);
void setascii(void);
void setbinary(void);
void setebcdic(void);
void settenex(void);
void tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0);
void setpassive(int argc, char *argv[]);
void setpeer(int argc, char *argv[]);
void cmdscanner(int top);
void pswitch(int flag);
void quit(void);
int login(char *host);
int command(char *fmt, ...);
int globulize(char **cpp);
void sendrequest(char *cmd, char *local, char *remote, int printnames);
void recvrequest(char *cmd, char *local, char *remote, char *mode,
int printnames);
int confirm(char *cmd, char *file);
void blkfree(char **av0);
int getit(int argc, char *argv[], int restartit, char *mode);
static int token(void);
int sleep(int time);
#include <windows.h>
#include <time.h>
#ifndef __GNUC__
#define EPOCHFILETIME (116444736000000000i64)
#else
#define EPOCHFILETIME (116444736000000000LL)
#endif
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
__inline int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
LARGE_INTEGER li;
__int64 t;
static int tzflag;
if (tv)
{
GetSystemTimeAsFileTime(&ft);
//li.LowPart = ft.dwLowDateTime;
//li.HighPart = ft.dwHighDateTime;
t = li.QuadPart; /* In 100-nanosecond intervals */
t -= EPOCHFILETIME; /* Offset to the Epoch time */
t /= 10; /* In microseconds */
tv->tv_sec = (long)(t / 1000000);
tv->tv_usec = (long)(t % 1000000);
}
if (tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}

View file

@ -0,0 +1,271 @@
/*
* Copyright (c) 1985 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef lint
static char sccsid[] = "@(#)ruserpass.c 5.1 (Berkeley) 3/1/89";
#endif /* not lint */
#include <sys/types.h>
#include <stdio.h>
//#include <utmp.h>
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>
#include "ftp_var.h"
#include "prototypes.h"
#include <winsock.h>
char *renvlook(), *index(), *getenv(), *getpass(), *getlogin();
void *malloc();
char *strcpy();
struct utmp *getutmp();
static FILE *cfile;
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
#define DEFAULT 1
#define LOGIN 2
#define PASSWD 3
#define ACCOUNT 4
#define MACDEF 5
#define ID 10
#define MACH 11
static char tokval[100];
static struct toktab {
char *tokstr;
int tval;
} toktab[]= {
"default", DEFAULT,
"login", LOGIN,
"password", PASSWD,
"passwd", PASSWD,
"account", ACCOUNT,
"machine", MACH,
"macdef", MACDEF,
0, 0
};
extern char *hostname;
int ruserpass(char *host, char **aname, char **apass, char **aacct)
{
char *hdir, buf[BUFSIZ], *tmp;
char myname[MAXHOSTNAMELEN], *mydomain;
int t, i, c, usedefault = 0;
struct stat stb;
extern int errno;
hdir = getenv("HOME");
if (hdir == NULL)
hdir = ".";
(void) sprintf(buf, "%s/.netrc", hdir);
cfile = fopen(buf, "r");
if (cfile == NULL) {
if (errno != ENOENT)
perror(buf);
return(0);
}
if (gethostname(myname, sizeof(myname)) < 0)
myname[0] = '\0';
if ((mydomain = index(myname, '.')) == NULL)
mydomain = "";
next:
while ((t = token())) switch(t) {
case DEFAULT:
usedefault = 1;
/* FALL THROUGH */
case MACH:
if (!usedefault) {
if (token() != ID)
continue;
/*
* Allow match either for user's input host name
* or official hostname. Also allow match of
* incompletely-specified host in local domain.
*/
if (strcasecmp(host, tokval) == 0)
goto match;
if (strcasecmp(hostname, tokval) == 0)
goto match;
if ((tmp = index(hostname, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
strncasecmp(hostname, tokval, tmp - hostname) == 0 &&
tokval[tmp - hostname] == '\0')
goto match;
if ((tmp = index(host, '.')) != NULL &&
strcasecmp(tmp, mydomain) == 0 &&
strncasecmp(host, tokval, tmp - host) == 0 &&
tokval[tmp - host] == '\0')
goto match;
continue;
}
match:
while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
case LOGIN:
if (token())
if (*aname == 0) {
*aname = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*aname, tokval);
} else {
if (strcmp(*aname, tokval))
goto next;
}
break;
case PASSWD:
if (strcmp(*aname, "anonymous") &&
fstat(fileno(cfile), &stb) >= 0 &&
(stb.st_mode & 077) != 0) {
fprintf(stderr, "Error - .netrc file not correct mode.\n");
fprintf(stderr, "Remove password or correct mode.\n");
goto bad;
}
if (token() && *apass == 0) {
*apass = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*apass, tokval);
}
break;
case ACCOUNT:
if (fstat(fileno(cfile), &stb) >= 0
&& (stb.st_mode & 077) != 0) {
fprintf(stderr, "Error - .netrc file not correct mode.\n");
fprintf(stderr, "Remove account or correct mode.\n");
goto bad;
}
if (token() && *aacct == 0) {
*aacct = malloc((unsigned) strlen(tokval) + 1);
(void) strcpy(*aacct, tokval);
}
break;
case MACDEF:
if (proxy) {
(void) fclose(cfile);
return(0);
}
while ((c=getc(cfile)) != EOF && c == ' ' || c == '\t');
if (c == EOF || c == '\n') {
printf("Missing macdef name argument.\n");
goto bad;
}
if (macnum == 16) {
printf("Limit of 16 macros have already been defined\n");
goto bad;
}
tmp = macros[macnum].mac_name;
*tmp++ = c;
for (i=0; i < 8 && (c=getc(cfile)) != EOF &&
!isspace(c); ++i) {
*tmp++ = c;
}
if (c == EOF) {
printf("Macro definition missing null line terminator.\n");
goto bad;
}
*tmp = '\0';
if (c != '\n') {
while ((c=getc(cfile)) != EOF && c != '\n');
}
if (c == EOF) {
printf("Macro definition missing null line terminator.\n");
goto bad;
}
if (macnum == 0) {
macros[macnum].mac_start = macbuf;
}
else {
macros[macnum].mac_start = macros[macnum-1].mac_end + 1;
}
tmp = macros[macnum].mac_start;
while (tmp != macbuf + 4096) {
if ((c=getc(cfile)) == EOF) {
printf("Macro definition missing null line terminator.\n");
goto bad;
}
*tmp = c;
if (*tmp == '\n') {
if (*(tmp-1) == '\0') {
macros[macnum++].mac_end = tmp - 1;
break;
}
*tmp = '\0';
}
tmp++;
}
if (tmp == macbuf + 4096) {
printf("4K macro buffer exceeded\n");
goto bad;
}
break;
default:
fprintf(stderr, "Unknown .netrc keyword %s\n", tokval);
break;
}
goto done;
}
done:
(void) fclose(cfile);
return(0);
bad:
(void) fclose(cfile);
return(-1);
}
static int token(void)
{
char *cp;
int c;
struct toktab *t;
if (feof(cfile))
return (0);
while ((c = getc(cfile)) != EOF &&
(c == '\r' || c == '\n' || c == '\t' || c == ' ' || c == ','))
continue;
if (c == EOF)
return (0);
cp = tokval;
if (c == '"') {
while ((c = getc(cfile)) != EOF && c != '"') {
if (c == '\\')
c = getc(cfile);
*cp++ = c;
}
} else {
*cp++ = c;
while ((c = getc(cfile)) != EOF
&& c != '\n' && c != '\t' && c != ' ' && c != ',' && c != '\r') {
if (c == '\\')
c = getc(cfile);
*cp++ = c;
}
}
*cp = 0;
if (tokval[0] == 0)
return (0);
for (t = toktab; t->tokstr; t++)
if (!strcmp(t->tokstr, tokval))
return (t->tval);
return (ID);
}