8#define _libncftp_ftp_c_
21static jmp_buf gCancelConnectJmp;
28static char gCopyright[] =
"@(#) LibNcFTP Copyright 1995-2000, by Mike Gleason. All rights reserved.";
36# define accept Raccept
37# define connect Rconnect
38# define getsockname Rgetsockname
39# define listen Rlisten
71 if (ip_address !=
NULL)
114 if ((
cp !=
NULL) && (
cp[1] !=
'\0')) {
121 for (curAlias = hp->
h_aliases; *curAlias !=
NULL; curAlias++) {
123 if ((
cp !=
NULL) && (
cp[1] !=
'\0')) {
139# if defined(HAVE_RES_INIT) && defined(HAVE__RES_DEFDNAME)
142 if ((_res.defdname !=
NULL) && (_res.defdname[0] !=
'\0')) {
154 fp =
fopen(
"/etc/resolv.conf",
"r");
163 if (
strcmp(tok,
"domain") == 0) {
318 Error(cip,
kDoPerror,
"Could not set out of band inline mode.\n");
332CancelConnect(
int signum)
338 longjmp(gCancelConnectJmp, 1);
353 volatile int sockfd = -1;
354 volatile int sock2fd = -1;
356 char **
volatile curaddr;
358 char *
volatile fhost;
366 const char *firstLine, *secondLine, *srvr;
392 fport = (
unsigned int)
htons((
unsigned short) fport);
460 sj =
setjmp(gCancelConnectJmp);
475 }
else if (
gGotSig == SIGALRM) {
545 sj =
setjmp(gCancelConnectJmp);
560 }
else if (
gGotSig == SIGALRM) {
598#elif defined(WSAENETDOWN)
603#elif defined(WSAENETUNREACH)
608#elif defined(WSAECONNABORTED)
613#elif defined(WSAETIMEDOUT)
618#elif defined(WSAEHOSTDOWN)
623#elif defined(WSAECONNRESET)
626 Error(cip,
kDoPerror,
"Could not connect to %s -- try again later.\n", fhost);
631#elif defined(WSAECONNREFUSED)
657#if defined(IP_TOS) && defined(IPTOS_LOWDELAY)
678 if ((sock2fd =
dup(sockfd)) < 0) {
681 Error(cip,
kDoPerror,
"Could not duplicate a file descriptor.\n");
711#ifdef HAVE_SETLINEBUF
712 setlinebuf(cip->
cin);
713 setlinebuf(cip->
cout);
752 if (
strstr(firstLine,
"Version wu-") !=
NULL) {
755 }
else if (
strstr(firstLine,
"NcFTPd") !=
NULL) {
757 srvr =
"NcFTPd Server";
758 }
else if (
STRNEQ(
"ProFTPD", firstLine, 7)) {
761 }
else if (
strstr(firstLine,
"Microsoft FTP Service") !=
NULL) {
763 srvr =
"Microsoft FTP Service";
764 }
else if (
strstr(firstLine,
"(NetWare ") !=
NULL) {
766 srvr =
"NetWare FTP Service";
767 }
else if (
STRNEQ(
"WFTPD", firstLine, 5)) {
770 }
else if (
STRNEQ(
"Serv-U FTP", firstLine, 10)) {
772 srvr =
"Serv-U FTP-Server";
773 }
else if (
strstr(firstLine,
"VFTPD") !=
NULL) {
776 }
else if (
STRNEQ(
"FTP-Max", firstLine, 7)) {
779 }
else if (
strstr(firstLine,
"Roxen") !=
NULL) {
782 }
else if (
strstr(firstLine,
"WS_FTP") !=
NULL) {
784 srvr =
"WS_FTP Server";
785 }
else if ((secondLine !=
NULL) && (
strstr(secondLine,
"WarFTP") !=
NULL)) {
791 PrintF(cip,
"Remote server is running %s.\n", srvr);
869#ifdef PRINTF_LONG_LONG
874 result =
RCmd(cip, rp,
"REST %ld", (
long) restartPt);
915#define UC(x) (int) (((int) x) & 0xff)
920 result =
RCmd(cip, rp,
"PORT %d,%d,%d,%d,%d,%d",
983 &
i[0], &
i[1], &
i[2], &
i[3], &
i[4], &
i[5]) != 6) {
988 for (
j=0, *weird = 0;
j<6;
j++) {
993 if ((
i[
j] < 0) || (
i[
j] > 255))
995 n[
j] = (
unsigned char) (
i[
j] & 0xff);
1016 unsigned short port;
1019 if (((
int) ephemLo == 0) || ((
int) ephemLo >= (
int) ephemHi)) {
1028 rangesize = (
int) ((
int) ephemHi - (
int) ephemLo);
1030 for (
i=0;
i<10;
i++) {
1031 port = (
unsigned short) (((
int)
rand() % rangesize) + (
int) ephemLo);
1191#elif defined(WSAECONNREFUSED)
1194 Error(cip,
kDontPerror,
"Server sent back a bogus port number.\nI will fall back to PORT instead of PASV mode.\n");
1230#if defined(IP_TOS) && defined(IPTOS_THROUGHPUT)
1255 unsigned short remoteDataPort;
1256 unsigned short remoteCtrlPort;
1279 if (newSocket < 0) {
1289 if ((
int) remoteDataPort != ((
int) remoteCtrlPort - 1)) {
1290 Error(cip,
kDontPerror,
"Data connection did not originate on correct port!\n");
1296 Error(cip,
kDontPerror,
"Data connection did not originate from remote server!\n");
int SClose(int sfd, int tlen)
int SConnect(int sfd, const struct sockaddr_in *const addr, int tlen)
char * Strncat(char *const, const char *const, const size_t)
char * Strncpy(char *const, const char *const, const size_t)
int strcmp(const char *String1, const char *String2)
char * strstr(char *String1, char *String2)
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
ACPI_SIZE strlen(const char *String)
char * strtok(char *String, const char *Delimiters)
char * strchr(const char *String, int ch)
#define STRNCPY(dst, src, n)
static const char * onoff(int bool)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
int SetTypeOfService(const FTPCIPtr, int, int)
int SetInlineOutOfBandData(const FTPCIPtr, int)
PHOSTENT WSAAPI gethostbyname(IN const char FAR *name)
INT WSAAPI gethostname(OUT char FAR *name, IN INT namelen)
GLboolean GLboolean GLboolean GLboolean a
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fdopen(_In_ int _FileHandle, _In_z_ const char *_Format)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl rand(void)
#define memcpy(s1, s2, n)
void SendTelnetInterrupt(const FTPCIPtr cip)
void CloseDataConnection(const FTPCIPtr cip)
static int Passive(const FTPCIPtr cip, struct sockaddr_in *saddr, int *weird)
void HangupOnServer(const FTPCIPtr cip)
static int GetSocketAddress(const FTPCIPtr cip, int sockfd, struct sockaddr_in *saddr)
char gLibNcFTPVersion[64]
int OpenDataConnection(const FTPCIPtr cip, int mode)
int SetStartOffset(const FTPCIPtr cip, longest_int restartPt)
int SetLinger(const FTPCIPtr cip, int sockfd, int onoff)
int GetOurHostName(char *host, size_t siz)
void CloseControlConnection(const FTPCIPtr cip)
static struct hostent * GetHostEntry(char *host, struct in_addr *ip_address)
int AcceptDataConnection(const FTPCIPtr cip)
int OpenControlConnection(const FTPCIPtr cip, char *host, unsigned int port)
int SetKeepAlive(const FTPCIPtr cip, int sockfd)
static int SendPort(const FTPCIPtr cip, struct sockaddr_in *saddr)
static int BindToEphemeralPortNumber(int sockfd, struct sockaddr_in *addrp, int ephemLo, int ephemHi)
int SetSockBufSize(int sockfd, size_t rsize, size_t ssize)
void PrintF(const FTPCIPtr cip, const char *const fmt,...)
#define kClosedFileDescriptor
void DisposeSReadlineInfo(SReadlineInfo *)
int InitSReadlineInfo(SReadlineInfo *, int, char *, size_t, int, int)
int sigsetjmp(sigjmp_buf buf, int savesigs)
void siglongjmp(sigjmp_buf buf, int val)
int RCmd(const FTPCIPtr, ResponsePtr, const char *,...)
#define kFirewallNotInUse
#define kServerTypeWS_FTP
#define kServerTypeNcFTPd
#define UNIMPLEMENTED_CMD(a)
#define kCommandAvailable
#define kServerTypeWuFTPd
void DoneWithResponse(const FTPCIPtr, ResponsePtr)
#define kServerTypeNetWareFTP
#define kServerTypeFTP_Max
#define kServerTypeServ_U
int GetResponse(const FTPCIPtr, ResponsePtr)
#define kServerTypeProFTPD
#define kServerTypeMicrosoftFTP
#define kFallBackToSendPortMode
#define kCommandNotAvailable
#define LIBNCFTP_USE_VAR(a)
ResponsePtr InitResponse(void)
#define kServerTypeWarFTPd
#define kServerTypeUnknown
#define kErrConnectRetryableErr
#define kErrBindDataSocket
#define kErrAcceptDataSocket
#define kErrSetTypeOfService
#define kErrListenDataSocket
#define kErrServerSentBogusPortNumber
#define kErrNewStreamSocket
#define kErrConnectMiscErr
#define kErrSetStartPoint
#define kErrPassiveModeFailed
#define kErrSetOutOfBandInline
#define kErrConnectRefused
#define kErrConnectDataSocket
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
struct sockaddr_in ourCtlAddr
struct sockaddr_in servDataAddr
unsigned int firewallPort
size_t dataSocketRBufSize
size_t ctrlSocketRBufSize
FTPConnectMessageProc onConnectMsgProc
struct sockaddr_in servCtlAddr
size_t ctrlSocketSBufSize
size_t dataSocketSBufSize
struct sockaddr_in ourDataAddr
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
void fatal(const char *msg)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList