summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanilo Almeida <dalmeida@mit.edu>2001-07-24 01:07:16 +0000
committerDanilo Almeida <dalmeida@mit.edu>2001-07-24 01:07:16 +0000
commit226d2461a7ddf2384faad5c20284fa80c5430ea6 (patch)
tree810f544e8e03967ab4449a44cdf60030bb42fe7c
parent27dee9d9f20638ec3de1170262ac1ba583776b1d (diff)
downloadkrb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.tar.gz
krb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.tar.xz
krb5-226d2461a7ddf2384faad5c20284fa80c5430ea6.zip
* Makefile.in, cmds.c, ftp.c, ftp_var.h, getpass.c, glob.c,
main.c, ruserpass.c, secure.c, secure.h: Quick and dirty Win32 port. Changes include using sockets more portably; changing the method of getting username, home directory, and temporary filenames; adding password reading code for Win32; directory enumeration via FindNextFile() rather than readdir(); removing OUT labels (which appear to cause problems with MSVC++ 6.0). Since ANSI C, assume we have stdarg.h. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@13628 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/appl/gssftp/ftp/ChangeLog11
-rw-r--r--src/appl/gssftp/ftp/Makefile.in26
-rw-r--r--src/appl/gssftp/ftp/cmds.c122
-rw-r--r--src/appl/gssftp/ftp/ftp.c410
-rw-r--r--src/appl/gssftp/ftp/ftp_var.h38
-rw-r--r--src/appl/gssftp/ftp/getpass.c80
-rw-r--r--src/appl/gssftp/ftp/glob.c52
-rw-r--r--src/appl/gssftp/ftp/main.c72
-rw-r--r--src/appl/gssftp/ftp/ruserpass.c5
-rw-r--r--src/appl/gssftp/ftp/secure.c6
-rw-r--r--src/appl/gssftp/ftp/secure.h4
11 files changed, 629 insertions, 197 deletions
diff --git a/src/appl/gssftp/ftp/ChangeLog b/src/appl/gssftp/ftp/ChangeLog
index be49ce6f6..868f0a579 100644
--- a/src/appl/gssftp/ftp/ChangeLog
+++ b/src/appl/gssftp/ftp/ChangeLog
@@ -1,3 +1,14 @@
+2001-07-23 Danilo Almeida <dalmeida@mit.edu>
+
+ * Makefile.in, cmds.c, ftp.c, ftp_var.h, getpass.c, glob.c,
+ main.c, ruserpass.c, secure.c, secure.h: Quick and dirty Win32
+ port. Changes include using sockets more portably; changing the
+ method of getting username, home directory, and temporary
+ filenames; adding password reading code for Win32; directory
+ enumeration via FindNextFile() rather than readdir(); removing OUT
+ labels (which appear to cause problems with MSVC++ 6.0). Since
+ ANSI C, assume we have stdarg.h.
+
2001-07-03 Ezra Peisach <epeisach@mit.edu>
* secure.c: Instead of hard wiring the FUDGE_FACTOR, new variables
diff --git a/src/appl/gssftp/ftp/Makefile.in b/src/appl/gssftp/ftp/Makefile.in
index 5739c8fa0..5bc282f55 100644
--- a/src/appl/gssftp/ftp/Makefile.in
+++ b/src/appl/gssftp/ftp/Makefile.in
@@ -15,27 +15,41 @@ SRCS = $(srcdir)/cmds.c $(srcdir)/cmdtab.c $(srcdir)/domacro.c \
$(srcdir)/ruserpass.c $(srcdir)/secure.c
-OBJS = cmds.o cmdtab.o domacro.o ftp.o getpass.o glob.o main.o \
- radix.o ruserpass.o secure.o
+OBJS = $(OUTPRE)cmds.$(OBJEXT) $(OUTPRE)cmdtab.$(OBJEXT) \
+ $(OUTPRE)domacro.$(OBJEXT) $(OUTPRE)ftp.$(OBJEXT) \
+ $(OUTPRE)getpass.$(OBJEXT) $(OUTPRE)glob.$(OBJEXT) \
+ $(OUTPRE)main.$(OBJEXT) $(OUTPRE)radix.$(OBJEXT) \
+ $(OUTPRE)ruserpass.$(OBJEXT) $(OUTPRE)secure.$(OBJEXT)
LOCALINCLUDES = -I$(srcdir)/.. -I$(srcdir) @KRB4_INCLUDES@
-all:: ftp
+#
+# We cannot have @KRB4_INCLUDES@ under Windows, since we do not use
+# configure, so we redefine LOCALINCLUDES not to have that.
+#
+
+##WIN32##LOCALINCLUDES = -I$(srcdir)/.. -I$(srcdir)
+
+all-unix:: ftp
+all-windows:: $(OUTPRE)ftp.exe
ftp: $(OBJS) $(GSS_DEPLIBS) $(KRB5_BASE_DEPLIBS)
$(CC_LINK) -o ftp $(OBJS) $(GSS_LIBS) $(KRB4COMPAT_LIBS)
-clean::
+$(OUTPRE)ftp.exe: $(OBJS) $(GLIB) $(KLIB)
+ link $(EXE_LINKOPTS) -out:$@ $** wsock32.lib advapi32.lib
+
+clean-unix::
$(RM) ftp
depend::
-install::
+install-unix::
for f in ftp; do \
$(INSTALL_PROGRAM) $$f \
$(DESTDIR)$(CLIENT_BINDIR)/`echo $$f|sed '$(transform)'`; \
$(INSTALL_DATA) $(srcdir)/$$f.M \
- ${DESTDIR}$(CLIENT_MANDIR)/`echo $$f|sed '$(transform)'`.1; \
+ $(DESTDIR)$(CLIENT_MANDIR)/`echo $$f|sed '$(transform)'`.1; \
done
ftp.o cmds.o main.o: $(srcdir)/../arpa/ftp.h
diff --git a/src/appl/gssftp/ftp/cmds.c b/src/appl/gssftp/ftp/cmds.c
index f0da69abf..4a242d6cf 100644
--- a/src/appl/gssftp/ftp/cmds.c
+++ b/src/appl/gssftp/ftp/cmds.c
@@ -44,10 +44,18 @@ static char sccsid[] = "@(#)cmds.c 5.26 (Berkeley) 3/5/91";
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-#include <sys/param.h>
+
+#include <port-sockets.h>
+
+#ifdef _WIN32
+#include <sys/stat.h>
+#include <direct.h>
+#include <mbstring.h>
+#undef ERROR
+#else
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/socket.h>
+#endif
#include <arpa/ftp.h>
@@ -55,10 +63,8 @@ static char sccsid[] = "@(#)cmds.c 5.26 (Berkeley) 3/5/91";
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <netdb.h>
#include <ctype.h>
#include <time.h>
-#include <netinet/in.h>
#ifdef HAVE_GETCWD
#define getwd(x) getcwd(x,MAXPATHLEN)
@@ -67,14 +73,9 @@ static char sccsid[] = "@(#)cmds.c 5.26 (Berkeley) 3/5/91";
#include "ftp_var.h"
#include "pathnames.h"
-#define sig_t my_sig_t
-#define sigtype krb5_sigtype
-typedef sigtype (*sig_t)();
-
extern char *globerr;
extern char *home;
extern char *remglob();
-extern char *getenv();
#ifndef HAVE_STRERROR
#define strerror(error) (sys_errlist[error])
#ifdef NEED_SYS_ERRLIST
@@ -207,7 +208,8 @@ void setpeer(argc, argv)
#endif
#endif
-#if defined(unix) && (NBBY == 8 || defined(linux))
+/* XXX - WIN32 - Is this really ok for Win32 (binary vs text mode)? */
+#if defined(unix) && (NBBY == 8 || defined(linux)) || defined(_WIN32)
/*
* this ifdef is to keep someone form "porting" this to an incompatible
* system and not checking this out. This way they have to think about it.
@@ -1038,7 +1040,11 @@ remglob(argv,doswitch)
char *argv[];
int doswitch;
{
+#ifdef _WIN32
+ char *temp = NULL;
+#else
char temp[16];
+#endif
static char buf[MAXPATHLEN];
static FILE *ftemp = NULL;
static char **args;
@@ -1065,9 +1071,17 @@ remglob(argv,doswitch)
return (cp);
}
if (ftemp == NULL) {
+#ifdef _WIN32
+ temp = _tempnam(_PATH_TMP, "ftpglob");
+ if (temp == NULL) {
+ printf("can't get temporary file name\n");
+ return (NULL);
+ }
+#else
(void) strncpy(temp, _PATH_TMP, sizeof(temp) - 1);
temp[sizeof(temp) - 1] = '\0';
(void) mktemp(temp);
+#endif /* !_WIN32 */
oldverbose = verbose, verbose = 0;
oldhash = hash, hash = 0;
if (doswitch) {
@@ -1081,6 +1095,10 @@ remglob(argv,doswitch)
verbose = oldverbose; hash = oldhash;
ftemp = fopen(temp, "r");
(void) unlink(temp);
+#ifdef _WIN32
+ free(temp);
+ temp = NULL;
+#endif /* _WIN32 */
if (ftemp == NULL) {
printf("can't find list of remote files, oops\n");
return (NULL);
@@ -1496,6 +1514,78 @@ usage:
* Do a shell escape
*/
/*ARGSUSED*/
+#ifdef _WIN32
+void shell(int argc, char **argv)
+{
+ char *AppName;
+ char ShellCmd[MAX_PATH];
+ char CmdLine[MAX_PATH];
+ int i;
+ PROCESS_INFORMATION ProcessInformation;
+ BOOL Result;
+ STARTUPINFO StartupInfo;
+ int NumBytes;
+
+#ifdef _DEBUG
+ if (trace)
+ {
+ fprintf(stderr, "entered shell\n");
+ fprintf(stderr, "arguments = \n");
+ fprintf(stderr, " argc = %d\n", argc);
+ for (i = 0; i < argc; i++)
+ {
+ fprintf(stderr, " argv %d = %s\n", i, argv[i]);
+ }
+ }
+#endif /* _DEBUG */
+
+ NumBytes = GetEnvironmentVariable("COMSPEC", ShellCmd, sizeof(ShellCmd));
+
+ if (NumBytes == 0)
+ {
+ code = -1;
+ return;
+ }
+
+ AppName = ShellCmd;
+ _mbscpy(CmdLine, ShellCmd);
+
+ if (argc > 1)
+ {
+ _mbsncat(CmdLine, " /C", sizeof(CmdLine));
+ }
+
+ for (i = 1; i < argc; i++)
+ {
+ _mbsncat(CmdLine, " ", sizeof(CmdLine));
+ _mbsncat(CmdLine, argv[i], sizeof(CmdLine));
+ }
+ CmdLine[sizeof(CmdLine)-1] = 0;
+
+ memset(&StartupInfo, 0, sizeof(StartupInfo));
+ StartupInfo.cb = sizeof(StartupInfo);
+ Result = CreateProcess(AppName, /* command name */
+ CmdLine, /* command line w/args */
+ NULL, /* sec attr (app) */
+ NULL, /* sec attr (thread) */
+ FALSE, /* inherit flags */
+ 0, /* creation flags */
+ NULL, /* environment */
+ NULL, /* working directory */
+ &StartupInfo, /* startup info struct */
+ &ProcessInformation); /* process info struct */
+
+ if (Result)
+ {
+ WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
+ CloseHandle(ProcessInformation.hProcess);
+ code = 0;
+ }
+ else {
+ code = -1;
+ }
+}
+#else
void shell(argc, argv)
int argc;
char **argv;
@@ -1555,6 +1645,7 @@ void shell(argc, argv)
}
return;
}
+#endif
/*
* Send new user information (re-login)
@@ -1806,17 +1897,17 @@ void quit()
void disconnect()
{
extern FILE *cout;
- extern int data;
+ extern SOCKET data;
if (!connected)
return;
(void) command("QUIT");
if (cout) {
- (void) fclose(cout);
+ (void) FCLOSE_SOCKET(cout);
+ cout = NULL;
}
- cout = NULL;
connected = 0;
- data = -1;
+ data = INVALID_SOCKET;
if (!proxy) {
macnum = 0;
}
@@ -1908,8 +1999,7 @@ void account(argc,argv)
jmp_buf abortprox;
static sigtype
-proxabort(sig)
- int sig;
+proxabort(int sig)
{
extern int proxy;
diff --git a/src/appl/gssftp/ftp/ftp.c b/src/appl/gssftp/ftp/ftp.c
index 452c71335..febc49cd4 100644
--- a/src/appl/gssftp/ftp/ftp.c
+++ b/src/appl/gssftp/ftp/ftp.c
@@ -61,18 +61,37 @@
static char sccsid[] = "@(#)ftp.c 5.38 (Berkeley) 4/22/91";
#endif /* not lint */
+#ifdef _WIN32
+#include <windows.h>
+#include <winsock.h>
+#include <sys/timeb.h>
+#include <time.h>
+#include <crtdbg.h>
+#undef ERROR
+#define NOSTBLKSIZE
+
+#define popen _popen
+#define pclose _pclose
+#define sleep(secs) Sleep(secs * 1000)
+int gettimeofday(struct timeval *tv, void *tz);
+
+#endif
+
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+
+#ifndef _WIN32
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#ifndef KRB5_KRB4_COMPAT
/* krb.h gets this, and Ultrix doesn't protect vs multiple inclusion */
#include <sys/socket.h>
+#include <netdb.h>
#endif
#include <sys/time.h>
#include <sys/file.h>
@@ -83,6 +102,9 @@ static char sccsid[] = "@(#)ftp.c 5.38 (Berkeley) 4/22/91";
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
+#include <pwd.h>
+#endif
+
#include <arpa/ftp.h>
#include <arpa/telnet.h>
@@ -90,22 +112,10 @@ static char sccsid[] = "@(#)ftp.c 5.38 (Berkeley) 4/22/91";
#include <signal.h>
#include <string.h>
#include <errno.h>
-#ifndef KRB5_KRB4_COMPAT
-/* krb.h gets this, and Ultrix doesn't protect vs multiple inclusion */
-#include <netdb.h>
-#endif
#include <fcntl.h>
-#include <pwd.h>
-#ifndef STDARG
-#if (defined(__STDC__) && ! defined(VARARGS)) || defined(HAVE_STDARG_H)
-#define STDARG
-#endif
-#endif
-#ifdef STDARG
#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+
+#include <port-sockets.h>
#ifndef L_SET
#define L_SET 0
@@ -154,18 +164,16 @@ static void abort_remote PROTOTYPE((FILE *));
static void tvsub PROTOTYPE((struct timeval *, struct timeval *, struct timeval *));
static char *gunique PROTOTYPE((char *));
-#define sig_t my_sig_t
-#define sigtype krb5_sigtype
-typedef sigtype (*sig_t)();
-
struct sockaddr_in hisctladdr;
struct sockaddr_in hisdataaddr;
struct sockaddr_in data_addr;
-int data = -1;
+SOCKET data = -1;
int abrtflag = 0;
int ptflag = 0;
struct sockaddr_in myctladdr;
+#ifndef _WIN32
uid_t getuid();
+#endif
sig_t lostpeer();
off_t restart_point = 0;
jmp_buf ptabort;
@@ -207,77 +215,87 @@ hookup(host, port)
return((char *) 0);
}
hisctladdr.sin_family = hp->h_addrtype;
- memcpy((caddr_t)&hisctladdr.sin_addr, hp->h_addr_list[0],
+ memcpy(&hisctladdr.sin_addr, hp->h_addr_list[0],
sizeof(hisctladdr.sin_addr));
(void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
}
hostname = hostnamebuf;
s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
- if (s < 0) {
- perror("ftp: socket");
+ if (s == INVALID_SOCKET) {
+ PERROR_SOCKET("ftp: socket");
code = -1;
return (0);
}
hisctladdr.sin_port = port;
- while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) {
+ while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) == SOCKET_ERROR) {
if (hp && hp->h_addr_list[1]) {
- int oerrno = errno;
+ int oerrno = SOCKET_ERRNO;
+#ifndef _WIN32
extern char *inet_ntoa();
-
+#endif
fprintf(stderr, "ftp: connect to address %s: ",
inet_ntoa(hisctladdr.sin_addr));
- errno = oerrno;
- perror((char *) 0);
+ SOCKET_SET_ERRNO(oerrno);
+ PERROR_SOCKET((char *) 0);
hp->h_addr_list++;
- memcpy((caddr_t)&hisctladdr.sin_addr,
+ memcpy(&hisctladdr.sin_addr,
hp->h_addr_list[0],
sizeof(hisctladdr.sin_addr));
fprintf(stdout, "Trying %s...\n",
inet_ntoa(hisctladdr.sin_addr));
- (void) close(s);
+ (void) closesocket(s);
s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
- if (s < 0) {
- perror("ftp: socket");
+ if (s == INVALID_SOCKET) {
+ PERROR_SOCKET("ftp: socket");
code = -1;
return (0);
}
continue;
}
- perror("ftp: connect");
+ PERROR_SOCKET("ftp: connect");
code = -1;
goto bad;
}
len = sizeof (myctladdr);
- if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
- perror("ftp: getsockname");
+ if (getsockname(s, (struct sockaddr *)&myctladdr, &len) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: getsockname");
code = -1;
goto bad;
}
#ifdef IP_TOS
#ifdef IPTOS_LOWDELAY
tos = IPTOS_LOWDELAY;
- if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
- perror("ftp: setsockopt TOS (ignored)");
+ if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: setsockopt TOS (ignored)");
+ }
#endif
#endif
- cin = fdopen(s, "r");
- cout = fdopen(s, "w");
+ cin = FDOPEN_SOCKET(s, "r");
+ cout = FDOPEN_SOCKET(s, "w");
if (cin == NULL || cout == NULL) {
fprintf(stderr, "ftp: fdopen failed.\n");
- if (cin)
- (void) fclose(cin);
- if (cout)
- (void) fclose(cout);
+ if (cin) {
+ (void) FCLOSE_SOCKET(cin);
+ cin = NULL;
+ }
+ if (cout) {
+ (void) FCLOSE_SOCKET(cout);
+ cout = NULL;
+ }
code = -1;
goto bad;
}
if (verbose)
printf("Connected to %s.\n", hostname);
if (getreply(0) > 2) { /* read startup message from server */
- if (cin)
- (void) fclose(cin);
- if (cout)
- (void) fclose(cout);
+ if (cin) {
+ (void) FCLOSE_SOCKET(cin);
+ cin = NULL;
+ }
+ if (cout) {
+ (void) FCLOSE_SOCKET(cout);
+ cout = NULL;
+ }
code = -1;
goto bad;
}
@@ -286,15 +304,15 @@ hookup(host, port)
int on = 1;
if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))
- < 0 && debug) {
- perror("ftp: setsockopt");
+ == SOCKET_ERROR && debug) {
+ PERROR_SOCKET("ftp: setsockopt");
}
}
#endif /* SO_OOBINLINE */
return (hostname);
bad:
- (void) close(s);
+ (void) closesocket(s);
return ((char *)0);
}
@@ -316,6 +334,7 @@ int login(host)
myname = getenv("LOGNAME");
if (myname == NULL)
myname = getenv("USER");
+#ifndef _WIN32
if (myname == NULL)
myname = getlogin();
if (myname == NULL) {
@@ -324,6 +343,16 @@ int login(host)
if (pp != NULL)
myname = pp->pw_name;
}
+#else
+ if (myname == NULL) {
+ static char buffer[200];
+ int len = sizeof(buffer);
+ if (GetUserName(buffer, &len))
+ myname = buffer;
+ else
+ myname = "<Unknown>";
+ }
+#endif
if (myname)
printf("Name (%s:%s): ", host, myname);
else
@@ -471,19 +500,10 @@ static int secure_command(cmd)
return(1);
}
-#ifdef STDARG
int command(char *fmt, ...)
-#else
-/*VARARGS*/
-int command(va_alist)
-va_dcl
-#endif
{
char in[FTP_BUFSIZ];
va_list ap;
-#ifndef STDARG
- char *fmt;
-#endif
int r;
sig_t oldintr;
@@ -491,12 +511,7 @@ va_dcl
if (debug) {
if (proxflag) printf("%s ", hostname);
printf("---> ");
-#ifdef STDARG
va_start(ap, fmt);
-#else
- va_start(ap);
- fmt = va_arg(ap, char *);
-#endif
if (strncmp("PASS ", fmt, 5) == 0)
printf("PASS XXXX");
else
@@ -511,12 +526,7 @@ va_dcl
return (0);
}
oldintr = signal(SIGINT, cmdabort);
-#ifdef STDARG
va_start(ap, fmt);
-#else
- va_start(ap);
- fmt = va_arg(ap, char *);
-#endif
vsprintf(in, fmt, ap);
va_end(ap);
again: if (secure_command(in) == 0)
@@ -531,7 +541,7 @@ again: if (secure_command(in) == 0)
goto again;
}
#endif
- if (abrtflag && oldintr != SIG_IGN)
+ if (abrtflag && oldintr && oldintr != SIG_IGN)
(*oldintr)(SIGINT);
(void) signal(SIGINT, oldintr);
return(r);
@@ -761,7 +771,7 @@ int getreply(expecteof)
(void) signal(SIGINT,oldintr);
if (code == 421 || originalcode == 421)
lostpeer();
- if (abrtflag && oldintr != cmdabort && oldintr != SIG_IGN)
+ if (abrtflag && oldintr && oldintr != cmdabort && oldintr != SIG_IGN)
(*oldintr)(SIGINT);
if (reply_parse) {
*reply_ptr = '\0';
@@ -802,23 +812,13 @@ abortsend(sig)
longjmp(sendabort, 1);
}
-#ifdef STDARG
void secure_error(char *fmt, ...)
-#else
-/* VARARGS1 */
-void secure_error(fmt, p1, p2, p3, p4, p5)
- char *fmt;
-#endif
{
-#ifdef STDARG
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
-#else
- fprintf(stderr, fmt, p1, p2, p3, p4, p5);
-#endif
putc('\n', stderr);
}
@@ -831,8 +831,8 @@ void sendrequest(cmd, local, remote, printnames)
struct stat st;
struct timeval start, stop;
register int c, d;
- FILE *volatile fin, *volatile dout = 0, *popen();
- int (*volatile closefunc)(), pclose(), fclose();
+ FILE *volatile fin, *volatile dout = 0;
+ int (*volatile closefunc)();
volatile sig_t oldintr, oldintp;
volatile long bytes = 0, hashbytes = HASHBYTES;
char *volatile lmode;
@@ -858,14 +858,16 @@ void sendrequest(cmd, local, remote, printnames)
while (cpend) {
(void) getreply(0);
}
- if (data >= 0) {
- (void) close(data);
- data = -1;
+ if (data != INVALID_SOCKET) {
+ (void) closesocket(data);
+ data = INVALID_SOCKET;
}
if (oldintr)
(void) signal(SIGINT,oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE,oldintp);
+#endif
code = -1;
return;
}
@@ -873,18 +875,29 @@ void sendrequest(cmd, local, remote, printnames)
if (strcmp(local, "-") == 0)
fin = stdin;
else if (*local == '|') {
+#ifdef SIGPIPE
oldintp = signal(SIGPIPE,SIG_IGN);
+#endif
fin = popen(local + 1, "r");
if (fin == NULL) {
perror(local + 1);
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
(void) signal(SIGPIPE, oldintp);
+#endif
code = -1;
return;
}
closefunc = pclose;
} else {
+#ifdef _WIN32
+ if ((curtype == TYPE_I) || (curtype == TYPE_L))
+ fin = fopen(local, "rb");
+ else
+ fin = fopen(local, "rt");
+#else /* !_WIN32 */
fin = fopen(local, "r");
+#endif /* !_WIN32 */
if (fin == NULL) {
fprintf(stderr, "local: %s: %s\n", local,
strerror(errno));
@@ -904,8 +917,10 @@ void sendrequest(cmd, local, remote, printnames)
}
if (initconn()) {
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
code = -1;
if (closefunc != NULL)
(*closefunc)(fin);
@@ -937,8 +952,10 @@ void sendrequest(cmd, local, remote, printnames)
if (remote) {
if (command("%s %s", cmd, remote) != PRELIM) {
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
if (closefunc != NULL)
(*closefunc)(fin);
return;
@@ -946,8 +963,10 @@ void sendrequest(cmd, local, remote, printnames)
} else
if (command("%s", cmd) != PRELIM) {
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
if (closefunc != NULL)
(*closefunc)(fin);
return;
@@ -956,7 +975,9 @@ void sendrequest(cmd, local, remote, printnames)
if (dout == NULL)
goto die;
(void) gettimeofday(&start, (struct timezone *)0);
+#ifdef SIGPIPE
oldintp = signal(SIGPIPE, SIG_IGN);
+#endif
switch (curtype) {
case TYPE_I:
@@ -1035,29 +1056,36 @@ void sendrequest(cmd, local, remote, printnames)
(void) gettimeofday(&stop, (struct timezone *)0);
if (closefunc != NULL)
(*closefunc)(fin);
- (void) fclose(dout);
+ (void) FCLOSE_SOCKET(dout);
+ dout = NULL;
(void) getreply(0);
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
if (bytes > 0)
ptransfer("sent", bytes, &start, &stop);
return;
die:
(void) gettimeofday(&stop, (struct timezone *)0);
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
if (!cpend) {
code = -1;
return;
}
- if (data >= 0) {
- (void) close(data);
- data = -1;
+ if (data != INVALID_SOCKET) {
+ (void) closesocket(data);
+ data = INVALID_SOCKET;
+ }
+ if (dout) {
+ (void) FCLOSE_SOCKET(dout);
+ dout = NULL;
}
- if (dout)
- (void) fclose(dout);
(void) getreply(0);
code = -1;
if (closefunc != NULL && fin != NULL)
@@ -1115,9 +1143,9 @@ void recvrequest(cmd, local, remote, lmode, printnames)
while (cpend) {
(void) getreply(0);
}
- if (data >= 0) {
- (void) close(data);
- data = -1;
+ if (data != INVALID_SOCKET) {
+ (void) closesocket(data);
+ data = INVALID_SOCKET;
}
if (oldintr)
(void) signal(SIGINT, oldintr);
@@ -1202,7 +1230,9 @@ void recvrequest(cmd, local, remote, lmode, printnames)
if (strcmp(local, "-") == 0)
fout = stdout;
else if (*local == '|') {
+#ifdef SIGPIPE
oldintp = signal(SIGPIPE, SIG_IGN);
+#endif
fout = popen(local + 1, "w");
if (fout == NULL) {
perror(local+1);
@@ -1210,7 +1240,16 @@ void recvrequest(cmd, local, remote, lmode, printnames)
}
closefunc = pclose;
} else {
+#ifdef _WIN32
+ int old_fmode = _fmode;
+
+ if ((curtype == TYPE_I) || (curtype == TYPE_L))
+ _fmode = _O_BINARY;
+#endif /* _WIN32 */
fout = fopen(local, lmode);
+#ifdef _WIN32
+ _fmode = old_fmode;
+#endif
if (fout == NULL) {
fprintf(stderr, "local: %s: %s\n", local,
strerror(errno));
@@ -1355,10 +1394,13 @@ break2:
if (closefunc != NULL)
(*closefunc)(fout);
(void) signal(SIGINT, oldintr);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintp);
+#endif
(void) gettimeofday(&stop, (struct timezone *)0);
- (void) fclose(din);
+ (void) FCLOSE_SOCKET(din);
+ din = NULL;
(void) getreply(0);
if (bytes > 0 && is_retr)
ptransfer("received", bytes, &start, &stop);
@@ -1368,8 +1410,10 @@ die:
/* abort using RFC959 recommended IP,SYNC sequence */
(void) gettimeofday(&stop, (struct timezone *)0);
+#ifdef SIGPIPE
if (oldintp)
(void) signal(SIGPIPE, oldintr);
+#endif
(void) signal(SIGINT, SIG_IGN);
if (!cpend) {
code = -1;
@@ -1379,14 +1423,16 @@ die:
abort_remote(din);
code = -1;
- if (data >= 0) {
- (void) close(data);
- data = -1;
+ if (data != INVALID_SOCKET) {
+ (void) closesocket(data);
+ data = INVALID_SOCKET;
}
if (closefunc != NULL && fout != NULL)
(*closefunc)(fout);
- if (din)
- (void) fclose(din);
+ if (din) {
+ (void) FCLOSE_SOCKET(din);
+ din = NULL;
+ }
if (bytes > 0)
ptransfer("received", bytes, &start, &stop);
(void) signal(SIGINT, oldintr);
@@ -1406,13 +1452,13 @@ static int initconn()
if (passivemode) {
data = socket(AF_INET, SOCK_STREAM, 0);
- if (data < 0) {
- perror("ftp: socket");
+ if (data == INVALID_SOCKET) {
+ PERROR_SOCKET("ftp: socket");
return(1);
}
if (options & SO_DEBUG &&
- setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) < 0)
- perror("ftp: setsockopt (ignored)");
+ setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: setsockopt (ignored)");
if (command("PASV") != COMPLETE) {
printf("Passive mode refused. Turning off passive mode.\n");
passivemode = 0;
@@ -1436,15 +1482,15 @@ static int initconn()
data_addr.sin_addr.s_addr = htonl((a1<<24)|(a2<<16)|(a3<<8)|a4);
data_addr.sin_port = htons((p1<<8)|p2);
- if (connect(data, (struct sockaddr *) &data_addr, sizeof(data_addr))<0) {
- perror("ftp: connect");
+ if (connect(data, (struct sockaddr *) &data_addr, sizeof(data_addr)) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: connect");
return(1);
}
#ifdef IP_TOS
#ifdef IPTOS_THROUGHPUT
on = IPTOS_THROUGHPUT;
- if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
- perror("ftp: setsockopt TOS (ignored)");
+ if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: setsockopt TOS (ignored)");
#endif
#endif
hisdataaddr = data_addr;
@@ -1456,34 +1502,34 @@ noport:
data_addr = myctladdr;
if (sendport)
data_addr.sin_port = 0; /* let system pick one */
- if (data != -1)
- (void) close(data);
+ if (data != INVALID_SOCKET)
+ (void) closesocket(data);
data = socket(AF_INET, SOCK_STREAM, 0);
- if (data < 0) {
- perror("ftp: socket");
+ if (data == INVALID_SOCKET) {
+ PERROR_SOCKET("ftp: socket");
if (tmpno)
sendport = 1;
return (1);
}
if (!sendport)
- if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)) < 0) {
- perror("ftp: setsockopt (reuse address)");
+ if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof (on)) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: setsockopt (reuse address)");
goto bad;
}
- if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) < 0) {
- perror("ftp: bind");
+ if (bind(data, (struct sockaddr *)&data_addr, sizeof (data_addr)) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: bind");
goto bad;
}
if (options & SO_DEBUG &&
- setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) < 0)
- perror("ftp: setsockopt (ignored)");
+ setsockopt(data, SOL_SOCKET, SO_DEBUG, (char *)&on, sizeof (on)) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: setsockopt (ignored)");
len = sizeof (data_addr);
- if (getsockname(data, (struct sockaddr *)&data_addr, &len) < 0) {
- perror("ftp: getsockname");
+ if (getsockname(data, (struct sockaddr *)&data_addr, &len) == SOCKET_ERROR) {
+ PERROR_SOCKET("ftp: getsockname");
goto bad;
}
- if (listen(data, 1) < 0)
- perror("ftp: listen");
+ if (listen(data, 1) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: listen");
if (sendport) {
a = (char *)&data_addr.sin_addr;
p = (char *)&data_addr.sin_port;
@@ -1504,13 +1550,13 @@ noport:
#ifdef IP_TOS
#ifdef IPTOS_THROUGHPUT
on = IPTOS_THROUGHPUT;
- if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) < 0)
- perror("ftp: setsockopt TOS (ignored)");
+ if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *)&on, sizeof(int)) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: setsockopt TOS (ignored)");
#endif
#endif
return (0);
bad:
- (void) close(data), data = -1;
+ (void) closesocket(data), data = INVALID_SOCKET;
if (tmpno)
sendport = 1;
return (1);
@@ -1523,25 +1569,25 @@ dataconn(lmode)
int s, fromlen = sizeof (hisdataaddr), tos;
#ifndef NO_PASSIVE_MODE
-if (passivemode)
- return (fdopen(data, lmode));
+ if (passivemode)
+ return (FDOPEN_SOCKET(data, lmode));
#endif
s = accept(data, (struct sockaddr *) &hisdataaddr, &fromlen);
- if (s < 0) {
- perror("ftp: accept");
- (void) close(data), data = -1;
+ if (s == INVALID_SOCKET) {
+ PERROR_SOCKET("ftp: accept");
+ (void) closesocket(data), data = INVALID_SOCKET;
return (NULL);
}
- (void) close(data);
+ (void) closesocket(data);
data = s;
#ifdef IP_TOS
#ifdef IPTOS_THROUGHPUT
tos = IPTOS_THROUGHPUT;
- if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) < 0)
- perror("ftp: setsockopt TOS (ignored)");
+ if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(int)) == SOCKET_ERROR)
+ PERROR_SOCKET("ftp: setsockopt TOS (ignored)");
#endif
#endif
- return (fdopen(data, lmode));
+ return (FDOPEN_SOCKET(data, lmode));
}
static void ptransfer(direction, bytes, t0, t1)
@@ -1704,7 +1750,8 @@ void pswitch(flag)
(void) signal(SIGINT, oldintr);
if (abrtflag) {
abrtflag = 0;
- (*oldintr)(SIGINT);
+ if (oldintr)
+ (*oldintr)(SIGINT);
}
}
@@ -1822,7 +1869,7 @@ die:
pswitch(!proxy);
if (cpend) {
FD_ZERO(&mask);
- FD_SET(fileno(cin), &mask);
+ FD_SET(SOCKETNO(fileno(cin)), &mask);
if ((nfnd = empty(&mask, 10)) <= 0) {
if (nfnd < 0) {
perror("abort");
@@ -1849,7 +1896,7 @@ void reset()
FD_ZERO(&mask);
while (nfnd > 0) {
- FD_SET(fileno(cin), &mask);
+ FD_SET(SOCKETNO(fileno(cin)), &mask);
if ((nfnd = empty(&mask,0)) < 0) {
perror("reset");
code = -1;
@@ -1912,6 +1959,27 @@ gunique(local)
char realm[REALM_SZ + 1];
#endif /* KRB5_KRB4_COMPAT */
+#ifdef _WIN32
+const gss_OID_desc krb5_gss_oid_array[] = {
+ /* this is the official, rfc-specified OID */
+ {9, "\052\206\110\206\367\022\001\002\002"},
+ /* this is the unofficial, wrong OID */
+ {5, "\053\005\001\005\002"},
+ /* this is the v2 assigned OID */
+ {9, "\052\206\110\206\367\022\001\002\003"},
+ /* these two are name type OID's */
+ {10, "\052\206\110\206\367\022\001\002\002\001"},
+ {10, "\052\206\110\206\367\022\001\002\002\002"},
+ { 0, 0 }
+};
+
+const gss_OID_desc * const gss_mech_krb5 = krb5_gss_oid_array+0;
+const gss_OID_desc * const gss_mech_krb5_old = krb5_gss_oid_array+1;
+const gss_OID_desc * const gss_mech_krb5_v2 = krb5_gss_oid_array+2;
+const gss_OID_desc * const gss_nt_krb5_name = krb5_gss_oid_array+3;
+const gss_OID_desc * const gss_nt_krb5_principal = krb5_gss_oid_array+4;
+#endif
+
#ifdef GSSAPI
struct {
const gss_OID_desc * const * mech_type;
@@ -2192,14 +2260,14 @@ FILE *din;
* after urgent byte rather than before as is protocol now
*/
sprintf(buf, "%c%c%c", IAC, IP, IAC);
- if (send(fileno(cout), buf, 3, MSG_OOB) != 3)
- perror("abort");
+ if (send(SOCKETNO(fileno(cout)), buf, 3, MSG_OOB) != 3)
+ PERROR_SOCKET("abort");
putc(DM, cout);
(void) secure_command("ABOR");
FD_ZERO(&mask);
- FD_SET(fileno(cin), &mask);
+ FD_SET(SOCKETNO(fileno(cin)), &mask);
if (din) {
- FD_SET(fileno(din), &mask);
+ FD_SET(SOCKETNO(fileno(din)), &mask);
}
if ((nfnd = empty(&mask, 10)) <= 0) {
if (nfnd < 0) {
@@ -2209,7 +2277,7 @@ FILE *din;
code = -1;
lostpeer();
}
- if (din && FD_ISSET(fileno(din), &mask)) {
+ if (din && FD_ISSET(SOCKETNO(fileno(din)), &mask)) {
/* Security: No threat associated with this read. */
while (read(fileno(din), buf, FTP_BUFSIZ) > 0)
/* LOOP */;
@@ -2270,3 +2338,61 @@ void secure_gss_error(maj_stat, min_stat, s)
return;
}
#endif /* GSSAPI */
+
+#ifdef _WIN32
+
+int gettimeofday(struct timeval *tv, void *tz)
+{
+ struct _timeb tb;
+ _tzset();
+ _ftime(&tb);
+ if (tv) {
+ tv->tv_sec = tb.time;
+ tv->tv_usec = tb.millitm * 1000;
+ }
+#if 0
+ if (tz) {
+ tz->tz_minuteswest = tb.timezone;
+ tz->tz_dsttime = tb.dstflag;
+ }
+#else
+ _ASSERTE(!tz);
+#endif
+ return 0;
+}
+
+int fclose_socket(FILE* f)
+{
+ int rc = 0;
+ SOCKET _s = _get_osfhandle(_fileno(f));
+
+ rc = fclose(f);
+ if (rc)
+ return rc;
+ if (closesocket(_s) == SOCKET_ERROR)
+ return SOCKET_ERRNO;
+ return 0;
+}
+
+FILE* fdopen_socket(SOCKET s, char* mode)
+{
+ int o_mode = 0;
+ int old_fmode = _fmode;
+ FILE* f = 0;
+
+ if (strstr(mode, "a+")) o_mode |= _O_RDWR | _O_APPEND;
+ if (strstr(mode, "r+")) o_mode |= _O_RDWR;
+ if (strstr(mode, "w+")) o_mode |= _O_RDWR;
+ if (strchr(mode, 'a')) o_mode |= _O_WRONLY | _O_APPEND;
+ if (strchr(mode, 'r')) o_mode |= _O_RDONLY;
+ if (strchr(mode, 'w')) o_mode |= _O_WRONLY;
+
+ /* In theory, _open_osfhandle only takes: _O_APPEND, _O_RDONLY, _O_TEXT */
+
+ _fmode = _O_BINARY;
+ f = fdopen(_open_osfhandle(s, o_mode), mode);
+ _fmode = old_fmode;
+
+ return f;
+}
+#endif
diff --git a/src/appl/gssftp/ftp/ftp_var.h b/src/appl/gssftp/ftp/ftp_var.h
index 67b187c01..ee02ed314 100644
--- a/src/appl/gssftp/ftp/ftp_var.h
+++ b/src/appl/gssftp/ftp/ftp_var.h
@@ -33,6 +33,33 @@
* @(#)ftp_var.h 5.9 (Berkeley) 6/1/90
*/
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#ifdef _WIN32
+int fclose_socket(FILE* f);
+FILE* fdopen_socket(SOCKET s, char* mode);
+#define FCLOSE_SOCKET(f) fclose_socket(f)
+#define FDOPEN_SOCKET(s, mode) fdopen_socket(s, mode)
+#define SOCKETNO(fd) _get_osfhandle(fd)
+#define PERROR_SOCKET(str) do { errno = SOCKET_ERRNO; perror(str); } while(0)
+#else
+#define FCLOSE_SOCKET(f) fclose(f)
+#define FDOPEN_SOCKET(s, mode) fdopen(s, fd)
+#define SOCKETNO(fd) (fd)
+#define PERROR_SOCKET(str) perror(str)
+#endif
+
+#ifdef _WIN32
+typedef void (*sig_t)(int);
+typedef void sigtype;
+#else
+#define sig_t my_sig_t
+#define sigtype krb5_sigtype
+typedef sigtype (*sig_t)();
+#endif
+
/*
* FTP global variables.
*/
@@ -74,7 +101,13 @@ 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 */
+#ifdef _WIN32
+#ifndef MAXPATHLEN
+#define MAXPATHLEN MAX_PATH
+#endif
+#else
#include <sys/param.h>
+#endif
extern char mapin[MAXPATHLEN]; /* input map template */
extern char mapout[MAXPATHLEN]; /* output map template */
extern int clevel; /* command channel protection level */
@@ -134,12 +167,11 @@ extern char macbuf[4096];
#endif
extern char *tail();
-extern int errno;
+#ifndef _WIN32
extern char *mktemp();
+#endif
-#if (defined(STDARG) || (defined(__STDC__) && ! defined(VARARGS))) || defined(HAVE_STDARG_H)
extern int command(char *, ...);
-#endif
#ifndef PROTOTYPE
#define PROTOTYPE(x) x
diff --git a/src/appl/gssftp/ftp/getpass.c b/src/appl/gssftp/ftp/getpass.c
index 622a32de9..3f2500481 100644
--- a/src/appl/gssftp/ftp/getpass.c
+++ b/src/appl/gssftp/ftp/getpass.c
@@ -8,6 +8,84 @@
static char sccsid[] = "@(#)getpass.c 1.1 90/04/28 SMI"; /* from UCB 5.4 3/7/86 */
#endif /* not lint */
+#ifdef _WIN32
+#include <io.h>
+#include <windows.h>
+#include <stdio.h>
+
+static DWORD old_mode;
+static HANDLE cons_handle;
+
+BOOL WINAPI
+GetPassConsoleControlHandler(DWORD dwCtrlType)
+{
+ switch(dwCtrlType){
+ case CTRL_BREAK_EVENT:
+ case CTRL_C_EVENT:
+ printf("Interrupt\n");
+ fflush(stdout);
+ (void) SetConsoleMode(cons_handle, old_mode);
+ ExitProcess(-1);
+ break;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+char *
+mygetpass(char *prompt)
+{
+ DWORD new_mode;
+ char *ptr;
+ int scratchchar;
+ static char password[50+1];
+ int pwsize = sizeof(password);
+
+ cons_handle = GetStdHandle(STD_INPUT_HANDLE);
+ if (cons_handle == INVALID_HANDLE_VALUE)
+ return NULL;
+ if (!GetConsoleMode(cons_handle, &old_mode))
+ return NULL;
+
+ new_mode = old_mode;
+ new_mode |= ( ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT );
+ new_mode &= ~( ENABLE_ECHO_INPUT );
+
+ if (!SetConsoleMode(cons_handle, new_mode))
+ return NULL;
+
+ SetConsoleCtrlHandler(&GetPassConsoleControlHandler, TRUE);
+
+ (void) fputs(prompt, stdout);
+ (void) fflush(stdout);
+ (void) memset(password, 0, pwsize);
+
+ if (fgets(password, pwsize, stdin) == NULL) {
+ if (ferror(stdin))
+ goto out;
+ (void) putchar('\n');
+ }
+ else {
+ (void) putchar('\n');
+
+ if ((ptr = strchr(password, '\n')))
+ *ptr = '\0';
+ else /* need to flush */
+ do {
+ scratchchar = getchar();
+ } while (scratchchar != EOF && scratchchar != '\n');
+ }
+
+out:
+ (void) SetConsoleMode(cons_handle, old_mode);
+ SetConsoleCtrlHandler(&GetPassConsoleControlHandler, FALSE);
+
+ return password;
+}
+
+#else /* !_WIN32 */
+
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
@@ -76,3 +154,5 @@ char *prompt;
(void) fclose(fi);
return(pbuf);
}
+
+#endif /* !_WIN32 */
diff --git a/src/appl/gssftp/ftp/glob.c b/src/appl/gssftp/ftp/glob.c
index 5ce2de62c..d0e7314af 100644
--- a/src/appl/gssftp/ftp/glob.c
+++ b/src/appl/gssftp/ftp/glob.c
@@ -39,15 +39,19 @@ static char sccsid[] = "@(#)glob.c 5.9 (Berkeley) 2/25/91";
* C-shell glob for random programs.
*/
-#include <sys/param.h>
#include <sys/stat.h>
-#include <dirent.h>
-#include <pwd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
+
+#ifndef _WIN32
+#include <sys/param.h>
+#include <dirent.h>
+#include <pwd.h>
+#endif
#ifdef POSIX
#include <limits.h>
@@ -77,7 +81,6 @@ static short gflag;
char **ftpglob();
char *globerr;
char *home;
-extern int errno;
static char *strspl PROTOTYPE((char *, char *)), *strend PROTOTYPE((char *));
char **copyblk PROTOTYPE((char **));
@@ -90,7 +93,9 @@ static int amatch PROTOTYPE((char *, char *)),
execbrc PROTOTYPE((char *, char *)), match PROTOTYPE((char *, char *));
static int digit PROTOTYPE((int)), letter PROTOTYPE((int)),
any PROTOTYPE((int, char *));
+#ifndef _WIN32
static int gethdir PROTOTYPE((char *));
+#endif
static int tglob PROTOTYPE((int ));
static int globcnt;
@@ -196,6 +201,7 @@ expand(as)
sgpathp = gpathp;
cs = as;
+#ifndef _WIN32
if (*cs == '~' && gpathp == gpath) {
addpath('~');
for (cs++; letter(*cs) || digit(*cs) || *cs == '-';)
@@ -212,6 +218,7 @@ expand(as)
gpathp = strend(gpath);
}
}
+#endif
while (!any(*cs, globchars)) {
if (*cs == 0) {
if (!globbed)
@@ -240,6 +247,38 @@ endit:
*gpathp = 0;
}
+#ifdef _WIN32
+
+static void
+matchdir(pattern)
+ char *pattern;
+{
+ HANDLE hFile = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATA file_data;
+ char *base = *gpath ? gpath : ".";
+ char *buffer = 0;
+
+ buffer = malloc(strlen(base) + strlen("\\*") + 1);
+ if (!buffer) return;
+ strcpy(buffer, base);
+ strcat(buffer, "\\*");
+ hFile = FindFirstFile(buffer, &file_data);
+ if (hFile == INVALID_HANDLE_VALUE) {
+ if (!globbed)
+ globerr = "Bad directory components";
+ return;
+ }
+ do {
+ if (match(file_data.cFileName, pattern)) {
+ Gcat(gpath, file_data.cFileName);
+ globcnt++;
+ }
+ } while (FindNextFile(hFile, &file_data));
+ FindClose(hFile);
+}
+
+#else /* !_WIN32 */
+
static void
matchdir(pattern)
char *pattern;
@@ -286,6 +325,8 @@ patherr2:
globerr = "Bad directory components";
}
+#endif /* !_WIN32 */
+
static int
execbrc(p, s)
char *p, *s;
@@ -710,6 +751,8 @@ strend(cp)
cp++;
return (cp);
}
+
+#ifndef _WIN32
/*
* Extract a home directory from the password file
* The argument points to a buffer where the name of the
@@ -726,3 +769,4 @@ static int gethdir(mhome)
(void) strcpy(mhome, pp->pw_dir);
return (0);
}
+#endif
diff --git a/src/appl/gssftp/ftp/main.c b/src/appl/gssftp/ftp/main.c
index 6937e4036..4f2cc59b2 100644
--- a/src/appl/gssftp/ftp/main.c
+++ b/src/appl/gssftp/ftp/main.c
@@ -53,12 +53,21 @@ static char sccsid[] = "@(#)main.c 5.18 (Berkeley) 3/1/91";
#include <stdio.h>
#include "ftp_var.h"
+#ifndef _WIN32
#ifndef KRB5_KRB4_COMPAT
/* krb.h gets this, and Ultrix doesn't protect vs multiple inclusion */
#include <sys/socket.h>
+#include <netdb.h>
#endif
#include <sys/ioctl.h>
#include <sys/types.h>
+#include <pwd.h>
+#endif /* !_WIN32 */
+
+#ifdef _WIN32
+#include <io.h>
+#undef ERROR
+#endif
#include <arpa/ftp.h>
@@ -66,17 +75,13 @@ static char sccsid[] = "@(#)main.c 5.18 (Berkeley) 3/1/91";
#include <string.h>
#include <errno.h>
#include <ctype.h>
-#ifndef KRB5_KRB4_COMPAT
-/* krb.h gets this, and Ultrix doesn't protect vs multiple inclusion */
-#include <netdb.h>
-#endif
-#include <pwd.h>
-#define sig_t my_sig_t
-#define sigtype krb5_sigtype
-typedef sigtype (*sig_t)();
+#include <port-sockets.h>
+#ifndef _WIN32
uid_t getuid();
+#endif
+
sigtype intr PROTOTYPE((int)), lostpeer PROTOTYPE((int));
extern char *home;
char *getlogin();
@@ -97,10 +102,20 @@ main(argc, argv)
{
register char *cp;
int top;
+#ifndef _WIN32
struct passwd *pw = NULL;
+#endif
char homedir[MAXPATHLEN];
char *progname = argv[0];
+#ifdef _WIN32
+ DWORD optionValue = SO_SYNCHRONOUS_NONALERT;
+ if (setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionValue, sizeof(optionValue)) == SOCKET_ERROR) {
+ fprintf(stderr, "ftp: cannot enable synchronous sockets\n");
+ exit(1);
+ }
+#endif
+
sp = getservbyname("ftp", "tcp");
if (sp == 0) {
fprintf(stderr, "ftp: ftp/tcp: unknown service\n");
@@ -197,6 +212,14 @@ main(argc, argv)
/*
* Set up the home directory in case we're globbing.
*/
+#ifdef _WIN32
+ cp = getenv("HOME");
+ if (cp != NULL) {
+ home = homedir;
+ (void) strncpy(home, cp, sizeof(homedir) - 1);
+ homedir[sizeof(homedir) - 1] = '\0';
+ }
+#else /* !_WIN32 */
cp = getlogin();
if (cp != NULL) {
pw = getpwnam(cp);
@@ -208,17 +231,22 @@ main(argc, argv)
(void) strncpy(home, pw->pw_dir, sizeof(homedir) - 1);
homedir[sizeof(homedir) - 1] = '\0';
}
+#endif /* !_WIN32 */
if (argc > 0) {
if (setjmp(toplevel))
exit(0);
(void) signal(SIGINT, intr);
+#ifdef SIGPIPE
(void) signal(SIGPIPE, lostpeer);
+#endif
setpeer(argc + 1, argv - 1);
}
top = setjmp(toplevel) == 0;
if (top) {
(void) signal(SIGINT, intr);
+#ifdef SIGPIPE
(void) signal(SIGPIPE, lostpeer);
+#endif
}
for (;;) {
cmdscanner(top);
@@ -239,21 +267,21 @@ lostpeer(sig)
int sig;
{
extern FILE *cout;
- extern int data;
+ extern SOCKET data;
extern char *auth_type;
extern int clevel;
extern int dlevel;
if (connected) {
if (cout != NULL) {
- (void) shutdown(fileno(cout), 1+1);
- (void) fclose(cout);
+ (void) shutdown(SOCKETNO(fileno(cout)), 1+1);
+ (void) FCLOSE_SOCKET(cout);
cout = NULL;
}
- if (data >= 0) {
+ if (data != INVALID_SOCKET) {
(void) shutdown(data, 1+1);
- (void) close(data);
- data = -1;
+ (void) closesocket(data);
+ data = INVALID_SOCKET;
}
connected = 0;
auth_type = NULL;
@@ -262,8 +290,8 @@ lostpeer(sig)
pswitch(1);
if (connected) {
if (cout != NULL) {
- (void) shutdown(fileno(cout), 1+1);
- (void) fclose(cout);
+ (void) shutdown(SOCKETNO(fileno(cout)), 1+1);
+ (void) FCLOSE_SOCKET(cout);
cout = NULL;
}
connected = 0;
@@ -347,7 +375,9 @@ cmdscanner(top)
break;
}
(void) signal(SIGINT, intr);
+#ifdef SIGPIPE
(void) signal(SIGPIPE, lostpeer);
+#endif
}
struct cmd *
@@ -432,7 +462,7 @@ S0:
switch (*sb) {
case '\0':
- goto OUT;
+ goto EXIT;
case ' ':
case '\t':
@@ -459,7 +489,7 @@ S1:
case ' ':
case '\t':
case '\0':
- goto OUT; /* end of token */
+ goto EXIT; /* end of token */
case '\\':
sb++; goto S2; /* slurp next character */
@@ -477,7 +507,7 @@ S2:
switch (*sb) {
case '\0':
- goto OUT;
+ goto EXIT;
default:
*ap++ = *sb++;
@@ -489,7 +519,7 @@ S3:
switch (*sb) {
case '\0':
- goto OUT;
+ goto EXIT;
case '"':
sb++; goto S1;
@@ -500,7 +530,7 @@ S3:
goto S3;
}
-OUT:
+EXIT:
if (got_one)
*ap++ = '\0';
argbase = ap; /* update storage pointer */
diff --git a/src/appl/gssftp/ftp/ruserpass.c b/src/appl/gssftp/ftp/ruserpass.c
index fdf0f0b67..fb9c72368 100644
--- a/src/appl/gssftp/ftp/ruserpass.c
+++ b/src/appl/gssftp/ftp/ruserpass.c
@@ -49,11 +49,14 @@ static char sccsid[] = "@(#)ruserpass.c 5.3 (Berkeley) 3/1/91";
#include <errno.h>
#include "ftp_var.h"
+#ifdef _WIN32
+#include <win-mac.h>
+#endif
+
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
-char *renvlook(), *getenv();
static int token PROTOTYPE((void));
static FILE *cfile;
diff --git a/src/appl/gssftp/ftp/secure.c b/src/appl/gssftp/ftp/secure.c
index 7062345f5..95c6ec848 100644
--- a/src/appl/gssftp/ftp/secure.c
+++ b/src/appl/gssftp/ftp/secure.c
@@ -20,6 +20,10 @@ extern MSG_DAT msg_data;
extern Key_schedule schedule;
#endif /* KRB5_KRB4_COMPAT */
+#ifdef _WIN32
+#undef ERROR
+#endif
+
#include <arpa/ftp.h>
#include <stdio.h>
@@ -31,7 +35,9 @@ extern Key_schedule schedule;
#include <unistd.h>
#endif
#include <sys/types.h>
+#ifndef _WIN32
#include <netinet/in.h>
+#endif
#include <errno.h>
#ifndef HAVE_STRERROR
diff --git a/src/appl/gssftp/ftp/secure.h b/src/appl/gssftp/ftp/secure.h
index 8a2a519f4..458daefc0 100644
--- a/src/appl/gssftp/ftp/secure.h
+++ b/src/appl/gssftp/ftp/secure.h
@@ -16,8 +16,4 @@ int secure_write PROTOTYPE((int, unsigned char *, unsigned int));
int secure_read PROTOTYPE((int, char *, unsigned int));
void secure_gss_error PROTOTYPE((OM_uint32 maj_stat, OM_uint32 min_stat, char *s));
-#if defined(STDARG) || (defined(__STDC__) && ! defined(VARARGS)) || defined(HAVE_STDARG_H)
void secure_error(char *, ...);
-#else
-void secure_error();
-#endif