From 2c80664e682be5d6da5d215436de1e7d1c2be500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Gro=C3=9Fmann?= Date: Wed, 8 Apr 2026 18:31:11 +0200 Subject: [PATCH] feat: remove embedded FTPD (~3,300 LOC, ~48 KB runtime) Delete all src/ftp*.c files (32 files) and include/ftpd.h. Extract UCHAR/USHRT/UINT/ULONG/U64 typedefs into include/types.h. Update include/httpcgi.h to use types.h instead of inline typedefs. In include/httpd.h: - Remove #include "ftpd.h", add #include "types.h" - Replace FTPD *ftpd field with void *unused_50 (offset-stable) In src/httpd.c: - Remove FTP listener creation and accept() from socket_thread - Remove FTPC eye-catcher branch from worker_thread - Remove ftpdterm() call from terminate() In src/httpdsrv.c: - Remove display_ftpd() and FTPD table row - Remove FTPC branch from display_queue_data() In src/httpcons.c: - Remove FTPD port display and FTPC branch from d_queue() Fixes #42 --- include/ftpd.h | 206 ------------------------- include/httpcgi.h | 5 +- include/httpd.h | 12 +- include/types.h | 13 ++ src/ftpcdsc.c | 82 ---------- src/ftpcgets.c | 65 -------- src/ftpcmsg.c | 58 ------- src/ftpcopen.c | 79 ---------- src/ftpcprtf.c | 46 ------ src/ftpcrecv.c | 172 --------------------- src/ftpcsend.c | 152 ------------------ src/ftpcterm.c | 65 -------- src/ftpdabor.c | 35 ----- src/ftpdcwd.c | 374 --------------------------------------------- src/ftpddele.c | 164 -------------------- src/ftpdlist.c | 12 -- src/ftpdmkd.c | 219 -------------------------- src/ftpdnoop.c | 10 -- src/ftpdpass.c | 72 --------- src/ftpdpasv.c | 82 ---------- src/ftpdpc.c | 205 ------------------------- src/ftpdpcs.c | 39 ----- src/ftpdport.c | 73 --------- src/ftpdpwd.c | 20 --- src/ftpdquit.c | 14 -- src/ftpdretr.c | 172 --------------------- src/ftpdrmd.c | 59 ------- src/ftpdsecs.c | 36 ----- src/ftpdstor.c | 85 ----------- src/ftpdsyst.c | 9 -- src/ftpdterm.c | 76 --------- src/ftpdtype.c | 39 ----- src/ftpduser.c | 53 ------- src/ftpfopen.c | 173 --------------------- src/ftpfqn.c | 382 ---------------------------------------------- src/ftpslist.c | 168 -------------------- src/httpcons.c | 28 ---- src/httpd.c | 121 --------------- src/httpdsrv.c | 206 +------------------------ 39 files changed, 17 insertions(+), 3864 deletions(-) delete mode 100644 include/ftpd.h create mode 100644 include/types.h delete mode 100644 src/ftpcdsc.c delete mode 100644 src/ftpcgets.c delete mode 100644 src/ftpcmsg.c delete mode 100644 src/ftpcopen.c delete mode 100644 src/ftpcprtf.c delete mode 100644 src/ftpcrecv.c delete mode 100644 src/ftpcsend.c delete mode 100644 src/ftpcterm.c delete mode 100644 src/ftpdabor.c delete mode 100644 src/ftpdcwd.c delete mode 100644 src/ftpddele.c delete mode 100644 src/ftpdlist.c delete mode 100644 src/ftpdmkd.c delete mode 100644 src/ftpdnoop.c delete mode 100644 src/ftpdpass.c delete mode 100644 src/ftpdpasv.c delete mode 100644 src/ftpdpc.c delete mode 100644 src/ftpdpcs.c delete mode 100644 src/ftpdport.c delete mode 100644 src/ftpdpwd.c delete mode 100644 src/ftpdquit.c delete mode 100644 src/ftpdretr.c delete mode 100644 src/ftpdrmd.c delete mode 100644 src/ftpdsecs.c delete mode 100644 src/ftpdstor.c delete mode 100644 src/ftpdsyst.c delete mode 100644 src/ftpdterm.c delete mode 100644 src/ftpdtype.c delete mode 100644 src/ftpduser.c delete mode 100644 src/ftpfopen.c delete mode 100644 src/ftpfqn.c delete mode 100644 src/ftpslist.c diff --git a/include/ftpd.h b/include/ftpd.h deleted file mode 100644 index 1bd6ac7..0000000 --- a/include/ftpd.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef FTPD_H -#define FTPD_H -/* -** FTP Daemon (server) -** Copyright (c) 2017 Mike Rayborn. All rights reserved. -*/ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "clibcrt.h" /* C runtime area for each task */ -#include "clibenv.h" /* C runtime environment vars */ -#include "clibstae.h" /* C runtime recovery routines */ -#include "socket.h" /* sockets via DYN75 */ -#include "clibwto.h" /* write to operator */ -#include "dbg.h" /* debugging goodies */ -#include "errors.h" /* the missing errno values */ -#include "clibthrd.h" /* basic threads */ -#include "clibthdi.h" /* thread management */ -#include "racf.h" /* security environment */ -#include "libufs.h" /* UFS client stubs via UFSD STC */ - -typedef struct ftpd FTPD; /* FTP Daemon (server) */ -typedef struct ftpc FTPC; /* FTP Client */ -typedef enum ftpstate FTPSTATE; /* FTP Client state */ -typedef struct ftpx FTPX; /* FTP function vector */ - -typedef unsigned char UCHAR; -typedef unsigned short USHRT; -typedef unsigned int UINT; -typedef unsigned long ULONG; -typedef unsigned long long U64; - -extern UCHAR *ebc2asc; -extern UCHAR *asc2ebc; -extern FTPD *ftpd; - -struct ftpd { - char eye[8]; /* 00 eye catcher */ -#define FTPD_EYE "*FTPD*" /* ... */ - CTHDTASK *ftpd_thread; /* 08 ftpd_thread subtask */ - FTPC **ftpc; /* 0C clients array */ - - unsigned addr; /* 10 our listener IP address */ - int port; /* 14 our listener port */ - int listen; /* 18 our listener socket */ - unsigned unused; /* 1C available */ - - FILE *stats; /* 20 statistics file (log) */ - FILE *dbg; /* 24 debug/trace output */ - volatile UCHAR flags; /* 28 processing flags */ -#define FTPD_FLAG_INIT 0x01 /* ... initializing */ -#define FTPD_FLAG_LISTENER 0x02 /* ... listener thread created */ -#define FTPD_FLAG_READY 0x04 /* ... ready */ -#define FTPD_FLAG_QUIESCE 0x40 /* ... don't accept new request */ -#define FTPD_FLAG_SHUTDOWN 0x80 /* ... shutdown now */ - UCHAR unused1[3]; /* 29 available */ - UFSSYS *sys; /* 2C Unix File System */ -}; /* 30 (48 bytes) */ - -enum ftpstate { - FTPSTATE_INITIAL=0, - FTPSTATE_LOGIN, - FTPSTATE_IDLE, - FTPSTATE_TRANSFER, - FTPSTATE_TERMINATE -}; - -/* each client is 4088 bytes (4096-8) */ -struct ftpc { - char eye[8]; /* 00 eye catcher */ -#define FTPC_EYE "*FTPC*" /* ... */ - FTPD *ftpd; /* 08 => FTPD (server) */ - ACEE *acee; /* 0C security environment */ - - double start; /* 10 start time in seconds */ - double end; /* 18 end time in seconds */ - - volatile UCHAR state; /* 20 current state (FTPSTATE) */ - UCHAR flags; /* 21 processing flags */ -#define FTPC_FLAG_PASSIVE 0x80 /* ... 1=passive mode */ -#define FTPC_FLAG_SEND 0x40 /* ... 1=sending data */ -#define FTPC_FLAG_RECV 0x20 /* ... 1=receiving data */ -#define FTPC_FLAG_FILE 0x10 /* ... 1=fp is FILE handle */ -#define FTPC_FLAG_UFS 0x08 /* ... 1=fp is UFS FILE handle */ -#define FTPC_FLAG_CWDPDS 0x04 /* ... 1=cwd is a PDS */ -#define FTPC_FLAG_CWDDS 0x02 /* ... 1=cwd is a dataset level */ -#define FTPC_FLAG_RNFR 0x01 /* ... 1=fp is RNFR name string */ - - char mode; /* 22 'S', 'B', 'C' */ -#define FTPC_MODE_STREAM 'S' -#define FTPC_MODE_BLOCK 'B' -#define FTPC_MODE_COMPRESSED 'C' - - char structure; /* 23 'F', 'R', 'P' */ -#define FTPC_STRUCTURE_FILE 'F' -#define FTPC_STRUCTURE_RECORD 'R' -#define FTPC_STRUCTURE_PAGE 'P' - - char type; /* 24 'A', 'E', 'I', 'L' */ -#define FTPC_TYPE_ASCII 'A' -#define FTPC_TYPE_EBCDIC 'E' -#define FTPC_TYPE_IMAGE 'I' -#define FTPC_TYPE_LOCAL 'L' - - UCHAR fflags; /* 25 file is flags */ -#define FTPC_FFLAG_MVS 0x80 /* ... MVS datasets */ -#define FTPC_FFLAG_UFS 0x40 /* ... Unix File System */ - - char unused[2]; /* 26 available */ - - int client_socket; /* 28 client socket */ - unsigned client_addr; /* 2C client IP address */ - int client_port; /* 30 client port */ - - int data_socket; /* 34 data socket */ - unsigned data_addr; /* 38 data IP address */ - int data_port; /* 3C data port */ - - void *fp; /* 40 file handle */ - unsigned len; /* 44 length of data in buf */ - unsigned pos; /* 48 position in buf */ - unsigned count; /* 4C bytes transfered */ - - UFS *ufs; /* 50 Unix File System handle */ - char cwd[252]; /* 54 cwd for datasets */ - int cmdlen; /* 150 length of data in cmd */ - char cmd[252]; /* 154 command buffer */ -#define FTPBUF (0x0FF8-0x0250) /* ... 4088-592 = 3496 */ - UCHAR buf[FTPBUF]; /* 250 data buffer */ - /* FF8 */ -}; /* FF8 (4088 bytes) */ - -extern int ftpdenter(const char *fmt, ...); -extern int ftpdexit(const char *fmt, ...); - -extern FTPD * ftpdinit(int argc, char **argv); -extern void ftpdterm(FTPD **ftpd); -extern int ftpdthrd(void *arg1, void *arg2); -extern double * ftpdsecs(double *secs); -extern void * ftpfopen(FTPC *ftpc, const char *fn, const char *fm, int fqnrc); - -/* client functions */ -extern void ftpcterm(FTPC **ftpc); -extern char * ftpcgets(FTPC *ftpc); -extern int ftpcmsg(FTPC *ftpc, char *msg, ...); -extern int ftpcopen(FTPC *ftpc); -extern int ftpcprtf(FTPC *ftpc, char *fmt, ...); - -/* FTPD inside HTTPD helpers */ -extern int ftpd_process_clients(void) asm("FTPDPCS"); -extern int ftpd_process_client(FTPC *ftpc) asm("FTPDPC"); - -/* FTPD command functions */ -extern int ftpdabor(FTPC *ftpc); /* Abort */ -extern int ftpdacct(FTPC *ftpc); /* Account */ -extern int ftpdallo(FTPC *ftpc); /* Allocate */ -extern int ftpdappe(FTPC *ftpc); /* Append */ -extern int ftpdcdup(FTPC *ftpc); /* Change Dir Up */ -extern int ftpdcwd (FTPC *ftpc); /* Change Working Dir */ -extern int ftpddele(FTPC *ftpc); /* Delete */ -extern int ftpdhelp(FTPC *ftpc); /* Help (211) */ -extern int ftpdlist(FTPC *ftpc); /* List (Directory) */ -extern int ftpdmkd (FTPC *ftpc); /* Make Directory */ -extern int ftpdmode(FTPC *ftpc); /* Mode */ -extern int ftpdnlst(FTPC *ftpc); /* Name List (Directory) */ -extern int ftpdnoop(FTPC *ftpc); /* No operation */ -extern int ftpdnoti(FTPC *ftpc); /* Command not implemented */ -extern int ftpdpass(FTPC *ftpc); /* Password */ -extern int ftpdpasv(FTPC *ftpc); /* Passive */ -extern int ftpdport(FTPC *ftpc); /* Port */ -extern int ftpdpwd (FTPC *ftpc); /* Print Working Dir */ -extern int ftpdquit(FTPC *ftpc); /* Quit */ -extern int ftpdrein(FTPC *ftpc); /* Reinitialize */ -extern int ftpdretr(FTPC *ftpc); /* Retrieve */ -extern int ftpdrmd (FTPC *ftpc); /* Remove Directory */ -extern int ftpdrnfr(FTPC *ftpc); /* Rename From */ -extern int ftpdrnft(FTPC *ftpc); /* Rename To */ -extern int ftpdsite(FTPC *ftpc); /* Site */ -extern int ftpdsmnt(FTPC *ftpc); /* Structure Mount */ -extern int ftpdstat(FTPC *ftpc); /* Status */ -extern int ftpdstor(FTPC *ftpc); /* Store */ -extern int ftpdstou(FTPC *ftpc); /* Store Unique */ -extern int ftpdstru(FTPC *ftpc); /* Structure */ -extern int ftpdsyst(FTPC *ftpc); /* System */ -extern int ftpdtype(FTPC *ftpc); /* Type (Data) */ -extern int ftpduser(FTPC *ftpc); /* User */ - -extern int ftpslist(FTPC *ftpc, int brief); -extern unsigned ftpc_ds_count(const char *level, const char *option, const char *filter) asm("FTPCDSC"); - -/* ftpfqn() - returns FTPFQN_RC_type */ -#define FTPFQN_RC_PARMS -2 /* invalid parameters */ -#define FTPFQN_RC_ERROR -1 /* Couldn't make sense of the input */ -#define FTPFQN_RC_PATH 0 /* out is a path name */ -#define FTPFQN_RC_HLQ 1 /* out is a high level qualifier */ -#define FTPFQN_RC_DSN 2 /* out is a dataset name */ -#define FTPFQN_RC_DSNMEM 3 /* out is a dataset(member) name */ -extern int ftpfqn(FTPC *ftpc, const char *in, char *out); - -#endif diff --git a/include/httpcgi.h b/include/httpcgi.h index 1b67ca3..88748a0 100644 --- a/include/httpcgi.h +++ b/include/httpcgi.h @@ -34,10 +34,7 @@ /* Basic typedefs (no dependency) */ /* ------------------------------------------------------------------ */ -typedef unsigned char UCHAR; -typedef unsigned short USHRT; -typedef unsigned int UINT; -typedef unsigned long ULONG; +#include "types.h" /* ------------------------------------------------------------------ */ /* Forward declarations — CGI modules hold pointers, never dereference */ diff --git a/include/httpd.h b/include/httpd.h index be17531..50873db 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -41,7 +41,7 @@ #include "dbg.h" /* debugging goodies */ #include "errors.h" /* the missing errno values */ #include "racf.h" /* security environment */ -#include "ftpd.h" /* FTP daemon and client */ +#include "types.h" /* UCHAR, USHRT, UINT, ULONG */ #include "cred.h" /* Credentials */ #include "mqtc370.h" /* MQTT Client */ #include "httpxlat.h" /* ASCII/EBCDIC translation */ @@ -63,14 +63,6 @@ typedef enum rdw RDW; /* RDW option */ #include "httppub.h" /* HTTP Telemetry Publisher */ -#if 0 /* declared in FTPD.H */ -typedef unsigned char UCHAR; -typedef unsigned short USHRT; -typedef unsigned int UINT; -typedef unsigned long ULONG; -typedef unsigned long long U64; -#endif - #ifndef OR #define OR ??!??! /* logical OR trigraph */ #endif @@ -122,7 +114,7 @@ struct httpd { char rname[12]; /* 38 resource name */ HTTPCGI **httpcgi; /* 44 CGI path and programs */ time64_t uptime; /* 48 Server startup time */ - FTPD *ftpd; /* 50 FTP daemon */ + void *unused_50; /* 50 (was: FTPD *ftpd) */ UFSSYS *ufssys; /* 54 Unix like file system */ LUAX *luax; /* 58 Lua function vector */ const char *version; /* 5C HTTPD Version */ diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..31bf87a --- /dev/null +++ b/include/types.h @@ -0,0 +1,13 @@ +#ifndef TYPES_H +#define TYPES_H +/* +** TYPES.H - Basic unsigned type definitions for HTTPD and CGI modules +*/ + +typedef unsigned char UCHAR; +typedef unsigned short USHRT; +typedef unsigned int UINT; +typedef unsigned long ULONG; +typedef unsigned long long U64; + +#endif diff --git a/src/ftpcdsc.c b/src/ftpcdsc.c deleted file mode 100644 index 8bd1e2e..0000000 --- a/src/ftpcdsc.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "ftpd.h" -#include "clibary.h" /* dynamic array prototypes */ -#include "clibdscb.h" /* DSCB structs and prototypes */ -#include "cliblist.h" /* __listc() */ -#include "clibstr.h" /* __patmat() */ - -static int parse(void *vdata, const char *fmt, ...); - -typedef struct { - const char *level; /* "HLQ.TEST" */ - const char *option; /* NULL or "NONVSAM VOLUME" */ - const char *filter; /* dataset name pattern "HLQ.TEST.*DATA" */ - unsigned count; /* number of datasets */ - char buf[256]; /* work buffer for parsing */ -} UDATA; - -unsigned -ftpc_ds_count(const char *level, const char *option, const char *filter) -{ - int rc = 0; - UDATA udata = {0}; - - udata.level = level; - udata.option = option; - udata.filter = filter; - - rc = __listc(level, option, parse, &udata); - - return udata.count; -} - -static int -parse(void *vdata, const char *fmt, ...) -{ - int rc = 0; - UDATA *udata = vdata; - char *buf = udata->buf; - char *p; - va_list arg; - - /* format the record passed to us by __listc() */ - va_start(arg, fmt); - vsprintf(buf, fmt, arg); - va_end(arg); - - // wtof("ftpc_ds_count:parse: \"%s\"", buf); - - if (buf[0]=='1') goto quit; /* skip page headers */ - - /* parse the formatted record looking for keywords */ - p = strtok(buf, " -\n"); - if (!p) goto quit; - - /* skip carriage control characters */ - if (isdigit(*p)) { - p++; - if (*p==0) p = strtok(NULL, " -\n"); - } - - if (stricmp(p, "NONVSAM")==0 || - stricmp(p, "PAGESPACE")==0 || - stricmp(p, "CLUSTER")==0 || - stricmp(p, "USERCATALOG")==0) { - /* get next parm */ - p = strtok(NULL, " -\n"); - if (!p) goto quit; - - /* make sure name does not start with a number */ - if (isdigit(*p)) goto quit; - - if (udata->filter) { - /* match dataset name against filter pattern */ - if (!__patmat(p, udata->filter)) goto quit; - } - - udata->count++; - goto quit; - } - -quit: - return 0; -} diff --git a/src/ftpcgets.c b/src/ftpcgets.c deleted file mode 100644 index a672f5b..0000000 --- a/src/ftpcgets.c +++ /dev/null @@ -1,65 +0,0 @@ -/* FTPCGETS.C */ -#include "httpd.h" - -char * -ftpcgets(FTPC *ftpc) -{ - CLIBGRT *grt = __grtget(); - HTTPD *httpd = grt->grtapp1; - char *ptr = 0; - time_t start; - time_t now; - fd_set read; - timeval wait; - int len; - int maxsock; - int rc; - unsigned char c; - - if (!ftpc) goto quit; - - ftpc->cmdlen = 0; - - /* set the wait interval */ - wait.tv_sec = 5; - wait.tv_usec = 0; - - time(&start); - - do { - /* read one character at a time from socket */ - memset(&read, 0, sizeof(fd_set)); - FD_SET(ftpc->client_socket, &read); - maxsock = ftpc->client_socket + 1; - - /* wait until we have something to read OR the client closes the socket */ - rc = selectex(maxsock, &read, NULL, NULL, &wait, NULL); - if (rc<0) break; /* client closed the socket */ - if (rc==0) { - time(&now); - if ((now - start) > (15*60)) break; /* 15 minutes have passed with no client input */ - if (httpd->flag & HTTPD_FLAG_QUIESCE) break; /* server is shutting down */ - continue; /* otherwise we keep waiting */ - } - - /* otherwise, we *should* have something to read */ - len = recv(ftpc->client_socket, &c, 1, 0); - /* wtof("%s recv(%d) len=%d, c=%02X", __func__, ftpc->client_socket, len, c); */ - if (len <= 0) break; - if (c==0x0D) continue; /* discard CR */ - if (c==0x0A) { /* done on LF */ - ptr = ftpc->cmd; - break; - } - /* convert character to EBCDIC and store in buffer */ - ftpc->cmd[ftpc->cmdlen++] = asc2ebc[c]; - } while (ftpc->cmdlen < (sizeof(ftpc->cmd)-1)); - - ftpc->cmd[ftpc->cmdlen] = 0; - -quit: -#if 0 - wtof("%s \"%s\"", __func__, ptr?ptr:"(null)"); -#endif - return ptr; -} diff --git a/src/ftpcmsg.c b/src/ftpcmsg.c deleted file mode 100644 index b6cf865..0000000 --- a/src/ftpcmsg.c +++ /dev/null @@ -1,58 +0,0 @@ -/* FTPCMSG.C */ -#include "httpd.h" - -/* Send message */ -int -ftpcmsg(FTPC *ftpc, char *msg, ...) -{ - int rc; - int len; - int i; - va_list args; - char *p; -#define BUFLEN 256 - char buf[BUFLEN+4]; - - /* print text and args to client */ - va_start(args, msg); - len = vsnprintf(buf, BUFLEN, msg, args); - va_end(args); - -#if 0 - buf[BUFLEN]=0; - wtof("%s \"%s\"", __func__, buf); -#endif - if (len > BUFLEN) { - len = BUFLEN; - buf[len] = 0; - } - - if (!strchr(buf, '\r')) { - buf[len++] = '\r'; - buf[len] = 0; - } - - if (!strchr(buf, '\n')) { - buf[len++] = '\n'; - buf[len]=0; - } - - for(i=0; i < len; i++) { - if (buf[i]=='\n') { - buf[i] = 0x0A; - continue; - } - buf[i] = ebc2asc[buf[i]]; - } - - for(p=buf; len > 0; len-=rc, p+=rc) { - rc = send(ftpc->client_socket, p, len, 0); - if (rc <= 0) { - /* abort transfer process */ - ftpc->state = FTPSTATE_TERMINATE; - break; - } - } - - return 0; -} diff --git a/src/ftpcopen.c b/src/ftpcopen.c deleted file mode 100644 index 862541e..0000000 --- a/src/ftpcopen.c +++ /dev/null @@ -1,79 +0,0 @@ -/* FTPCOPEN.C */ -#include "httpd.h" - -/* open data connection, returns socket number *or* -1 for error */ -int -ftpcopen(FTPC *ftpc) -{ - int rc; - struct sockaddr_in sockaddr_in = {0}; - int len = sizeof(sockaddr_in); - int maxsock = 0; - timeval wait = {0}; - fd_set read = {0}; - - if (ftpc->data_socket >= 0) { - /* if we have a data socket, we assume it's a listener socket */ - ftpc->flags &= 0xFF - FTPC_FLAG_PASSIVE; /* reset the passive flag */ - ftpcmsg(ftpc, "150 Listening for data connection"); - - /* set the wait interval */ - wait.tv_sec = 30; - wait.tv_usec = 0; - - /* build fd_set for listener socket */ - FD_SET(ftpc->data_socket, &read); - maxsock = ftpc->data_socket + 1; - - /* wait for connection from FTP client */ - rc = select(maxsock, &read, NULL, NULL, &wait); - /* wtof("%s select() rc=%d", __func__, rc); */ - if (rc < 0) goto quit; - if (rc==0) { - /* timeout */ - rc = -1; /* so that quit will close the socket */ - goto quit; - } - - /* accept connection from FTP client */ - rc = accept(ftpc->data_socket, &sockaddr_in, &len); - /* wtof("%s accept() rc=%d", __func__, rc); */ - - /* we close the listener socket and return the new socket or error */ - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - goto quit; - } - - rc = socket(AF_INET, SOCK_STREAM, 0); - if (rc < 0) goto quit; - ftpc->data_socket = rc; - - sockaddr_in.sin_family = AF_INET; - sockaddr_in.sin_port = htons(ftpc->data_port); - sockaddr_in.sin_addr.s_addr = htonl(ftpc->data_addr); - rc = connect(ftpc->data_socket, &sockaddr_in, len); - if (rc < 0) goto quit; - - rc = ftpc->data_socket; - ftpcmsg(ftpc,"150 Data connection opened"); - -quit: - if (rc < 0) { - /* an error occured */ - if (ftpc->data_socket >= 0) { - /* close the data socket */ - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - } - else { - /* set non-blocking on the new socket (rc) */ - len = 1; - if (ioctlsocket(rc, FIONBIO, &len)) { - wtof("FTPD053E Unable to set non-blocking I/O for socket %d\n", - rc); - } - } - return rc; -} diff --git a/src/ftpcprtf.c b/src/ftpcprtf.c deleted file mode 100644 index a9c9441..0000000 --- a/src/ftpcprtf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* FTPCPRTF.C */ -#include "httpd.h" - -/* Send formatted string to data connection */ -int -ftpcprtf(FTPC *ftpc, char *fmt, ...) -{ - int sent = 0; - int rc; - int len; - int i; - va_list args; - char buf[4096]; - - /* print text and args to client data connection */ - va_start(args, fmt); - len = vsprintf(buf, fmt, args); - va_end(args); - - /* wtodumpf(buf, len, "%s ebcdic", __func__); */ - for(i=0; i < len; i++) { - if (buf[i]=='\n') { - buf[i] = 0x0A; - continue; - } - buf[i] = ebc2asc[buf[i]]; - } - /* wtodumpf(buf, len, "%s ascii", __func__); */ - - /* the data socket is non-blocking, so we do our send in a loop */ - for(i=0; i < len; i += rc) { - rc = send(ftpc->data_socket, &buf[i], len-i, 0); - if (rc < 0) { - if (errno==EWOULDBLOCK) { - /* send would have blocked, so we continue our attempts */ - rc = 0; - continue; - } - wtof("%s send() rc=%d, errno=%d", __func__, rc, errno); - return rc; - } - sent += rc; - } - - return sent; -} diff --git a/src/ftpcrecv.c b/src/ftpcrecv.c deleted file mode 100644 index 6d77bb3..0000000 --- a/src/ftpcrecv.c +++ /dev/null @@ -1,172 +0,0 @@ -/* FTPCRECV.C */ -#include "httpd.h" - -int -ftpcrecv(FTPC *ftpc) -{ - int rc = 0; - int iseof = 0; - int len; - int i; - unsigned char *ptr; - - if (!ftpc) goto quit; - - if (!ftpc->fp) { - ftpcmsg(ftpc, "552 Requested file action aborted"); - if (ftpc->data_socket >= 0) { - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - goto quit; - } - - if (ftpc->state == FTPSTATE_IDLE) { - /* wtof("%s FTPSTATE_IDLE", __func__); */ - rc = ftpcopen(ftpc); - /* wtof("%s ftpcopen() rc=%d", __func__, rc); */ - if (rc < 0) { - ftpcmsg(ftpc, "425 Can't open data connection"); - if (ftpc->fp) { - if (ftpc->fflags & FTPC_FFLAG_MVS) { - fclose(ftpc->fp); - ftpc->fp = 0; - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - ufs_fclose((UFSFILE **)&ftpc->fp); - } - } - goto quit; - } - ftpc->data_socket = rc; - } - - /* wtof("%s FTPSTATE_TRANSFER", __func__); */ - ftpc->state = FTPSTATE_TRANSFER; - - /* receive data from client */ - len = sizeof(ftpc->buf) - ftpc->len; - /* wtof("%s sizeof(ftpc->buf)=%d, ftpc->len=%d, len=%d", __func__, sizeof(ftpc->buf), ftpc->len, len); */ - if (!len) goto saveit; - - ptr = &ftpc->buf[ftpc->len]; - len = recv(ftpc->data_socket, ptr, len, 0); - /* wtof("%s recv(%d) len=%d", __func__, ftpc->data_socket, len); */ - if (len==0) { - /* nothing received */ - iseof = 1; - goto saveit; - } - if (len < 0) { - /* wtof("%s errno=%d", __func__, errno); */ - if (errno == EWOULDBLOCK) { - /* no data available */ - rc = 0; - goto quit; - } - iseof = 1; - goto saveit; - } - - /* ptr[len] = 0; */ - - if (ftpc->type == FTPC_TYPE_ASCII) { - /* wtof("%s FTPC_TYPE_ASCII", __func__); */ - /* convert buffer to EBCDIC */ - for(i=0; i < len; i++) { - if (ptr[i]==0x0D) { - /* discard CR */ - int move = len - (i+1); - if (move > 0) { - /* wtof("%s memcpy(%08X, %08X, %d) i=%d, len=%d", - __func__, &ptr[i], &ptr[i+1], move, i, len); */ - memcpy(&ptr[i], &ptr[i+1], move); - /* wtof("%s memcpy() okay", __func__); */ - } - len--; - i--; - continue; - } - if (ptr[i]==0x0A) { - /* convert LF to newline */ - ptr[i] = '\n'; - continue; - } - ptr[i] = asc2ebc[ptr[i]]; - } - } - ftpc->len += len; - ftpc->count += len; - -saveit: - if (ftpc->fflags & FTPC_FFLAG_MVS) { - /* wtof("%s FTPC_FFLAG_MVS", __func__); */ - for(; ftpc->pos < ftpc->len; ftpc->pos++) { - rc = fputc(ftpc->buf[ftpc->pos], ftpc->fp); - if (rc==EOF) goto eof; - } - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - UINT32 len = ftpc->len - ftpc->pos; - UINT32 n; - - /* wtof("%s FTPC_FFLAG_UFS", __func__); */ - - if (len > 0) { - /* wtodumpf(&ftpc->buf[ftpc->pos], len, "%s write buffer", __func__); */ - n = ufs_fwrite(&ftpc->buf[ftpc->pos], 1, len, ftpc->fp); - /* wtof("%s %u = ufs_fwrite(%08X, 1, %u, %08X)", - __func__, n, &ftpc->buf[ftpc->pos], len, ftpc->fp); */ - /* wtof("%s len=%u, n=%u", __func__, len, n); */ - - if (n!=len) goto eof; - ftpc->pos += n; - } - } - - /* wtof("%s ftpc->pos=%u, ftpc->len=%u", __func__, ftpc->pos, ftpc->len); */ - if (ftpc->pos == ftpc->len) { - /* buffer is empty */ - /* wtof("%s buffer is empty", __func__); */ - ftpc->len = 0; - ftpc->pos = 0; - } - - rc = 0; - if (!iseof) goto quit; - -eof: - /* wtof("%s EOF", __func__); */ - ftpc->len = 0; - ftpc->pos = 0; - if (ftpc->data_socket >= 0) { - ftpcmsg(ftpc, "226 Closing data connection"); - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - if (ftpc->fp) { - if (ftpc->fflags & FTPC_FFLAG_MVS) { - fclose(ftpc->fp); - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - ufs_fclose((UFSFILE **)&ftpc->fp); - } - ftpc->fp = 0; - ftpc->fflags = 0; - } - - if (ftpc->state == FTPSTATE_TRANSFER) { - /* save file transfer stats */ - ftpdsecs(&ftpc->end); - /* ftpcstat(ftpc); */ - ftpc->state = FTPSTATE_IDLE; - /* wtof("%s FTPSTATE_IDLE", __func__); */ - ftpc->flags &= 0xFF - FTPC_FLAG_RECV; - } - -quit: - return rc; -} diff --git a/src/ftpcsend.c b/src/ftpcsend.c deleted file mode 100644 index 3b325ca..0000000 --- a/src/ftpcsend.c +++ /dev/null @@ -1,152 +0,0 @@ -/* FTPCSEND.C */ -#include "httpd.h" - -int -ftpcsend(FTPC *ftpc) -{ - int rc = 0; - int len; - int i; - char *ptr; - - if (!ftpc) goto quit; - - if (ftpc->state == FTPSTATE_IDLE) { - rc = ftpcopen(ftpc); - if (rc < 0) { - ftpcmsg(ftpc, "425 Can't open data connection"); - if (ftpc->fp) { - if (ftpc->fflags & FTPC_FFLAG_MVS) { - fclose(ftpc->fp); - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - ufs_fclose((UFSFILE **)&ftpc->fp); - } - ftpc->fp = 0; - } - ftpc->flags &= 0xFF - FTPC_FLAG_SEND; - goto quit; - } - ftpc->data_socket = rc; - } - - if (!ftpc->fp) { - ftpcmsg(ftpc, "550 Requested file unavailable"); - if (ftpc->data_socket >= 0) { - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - goto quit; - } - - ftpc->state = FTPSTATE_TRANSFER; - if (ftpc->pos == ftpc->len) { - /* buffer is empty */ - ftpc->len = 0; - ftpc->pos = 0; - - if (ftpc->fflags & FTPC_FFLAG_MVS) { - if (ftpc->type == FTPC_TYPE_ASCII || - ftpc->type == FTPC_TYPE_EBCDIC) { - ptr = fgets(ftpc->buf, sizeof(ftpc->buf), ftpc->fp); - if (!ptr) goto eof; - - len = strlen(ftpc->buf); - /* wtodumpf(ftpc->buf, len, "ftpcsend"); */ - - if (ftpc->type == FTPC_TYPE_ASCII) { - /* convert buffer to ASCII */ - char *p = strchr(ftpc->buf, '\n'); - if (p) { - strcpy(p, "\r\n"); - len++; - } - for(i=0; i < len; i++) { - if (ftpc->buf[i]=='\n') { - ftpc->buf[i] = 0x0A; - continue; - } - ftpc->buf[i] = ebc2asc[ftpc->buf[i]]; - } - } - } - else { - len = fread(ftpc->buf, 1, sizeof(ftpc->buf), ftpc->fp); - if (len <= 0) goto eof; - } - ftpc->len = len; - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - if (ftpc->type == FTPC_TYPE_ASCII || - ftpc->type == FTPC_TYPE_EBCDIC) { - ptr = ufs_fgets(ftpc->buf, sizeof(ftpc->buf), ftpc->fp); - if (!ptr) goto eof; - - len = strlen(ftpc->buf); - /* wtodumpf(ftpc->buf, len, "ftpcsend"); */ - - if (ftpc->type == FTPC_TYPE_ASCII) { - /* convert buffer to ASCII */ - char *p = strchr(ftpc->buf, '\n'); - if (p) { - strcpy(p, "\r\n"); - len++; - } - for(i=0; i < len; i++) { - if (ftpc->buf[i]=='\n') { - ftpc->buf[i] = 0x0A; - continue; - } - ftpc->buf[i] = ebc2asc[ftpc->buf[i]]; - } - } - } - else { - len = ufs_fread(ftpc->buf, 1, sizeof(ftpc->buf), ftpc->fp); - if (len <= 0) goto eof; - } - ftpc->len = len; - } - } - - /* send data to client */ - len = ftpc->len - ftpc->pos; - len = send(ftpc->data_socket, &ftpc->buf[ftpc->pos], len, 0); - if (len >= 0) { - ftpc->pos += len; - ftpc->count += len; - goto quit; - } - -eof: - ftpc->len = 0; - ftpc->pos = 0; - if (ftpc->data_socket >= 0) { - ftpcmsg(ftpc, "226 Closing data connection"); - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - if (ftpc->fp) { - if (ftpc->fflags & FTPC_FFLAG_MVS) { - fclose(ftpc->fp); - } - else if (ftpc->fflags & FTPC_FFLAG_UFS) { - /* UFS file system access */ - ufs_fclose((UFSFILE **)&ftpc->fp); - } - ftpc->fp = 0; - ftpc->fflags = 0; - } - if (ftpc->state == FTPSTATE_TRANSFER) { - /* save file transfer stats */ - ftpdsecs(&ftpc->end); - /* ftpcstat(ftpc); */ - ftpc->state = FTPSTATE_IDLE; - ftpc->flags &= 0xFF - FTPC_FLAG_SEND; - } - -quit: - return rc; -} diff --git a/src/ftpcterm.c b/src/ftpcterm.c deleted file mode 100644 index 58f9ba8..0000000 --- a/src/ftpcterm.c +++ /dev/null @@ -1,65 +0,0 @@ -/* FTPCTERM.C */ -#include "httpd.h" - -void -ftpcterm(FTPC **ppftpc) -{ - FTPC *ftpc; - FTPD *ftpd; - - if (!ppftpc) goto quit; - ftpc = *ppftpc; - if (!ftpc) goto quit; - - if (ftpc->data_socket >= 0) { - /* close data socket */ - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - - if (ftpc->client_socket >= 0) { - /* close client socket */ - closesocket(ftpc->client_socket); - ftpc->client_socket = -1; - } - - if (ftpc->fp) { - /* close data file */ - fclose(ftpc->fp); - ftpc->fp = 0; - } - - ftpd = ftpc->ftpd; - /* this *should* always be true */ - if (ftpd) { - if (ftpd->sys) { - /* unix like file system exist */ - if (ftpc->ufs) { - /* sync file system buffers to disk */ - ufs_sync(ftpc->ufs); - - /* terminate Unix File System access */ - ufsfree(&ftpc->ufs); - } - } - } - - if (ftpc->acee) { - ACEE *acee = ftpc->acee; - char *name = acee->aceeuser; - int len = name[0]; - - wtof("HTTPD203I FTP connection terminated for '%*.*s'", - len, len, &name[1]); - - racf_logout(&ftpc->acee); - ftpc->acee = 0; - } - - /* free the FTPC handle */ - free(ftpc); - *ppftpc = 0; - -quit: - return; -} diff --git a/src/ftpdabor.c b/src/ftpdabor.c deleted file mode 100644 index be1e763..0000000 --- a/src/ftpdabor.c +++ /dev/null @@ -1,35 +0,0 @@ -/* FTPDABOR.C */ -#include "httpd.h" - -int -ftpdabor(FTPC *ftpc) -{ - if (ftpc->state == FTPSTATE_TRANSFER) { - /* cancel the transfer */ - if (ftpc->data_socket >= 0) { - ftpcmsg(ftpc, "226 Closing data connection"); - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - if (ftpc->fp) { - fclose(ftpc->fp); - ftpc->fp = NULL; - } - ftpc->flags &= (0xFF - (FTPC_FLAG_SEND + FTPC_FLAG_RECV)); - ftpc->state = FTPSTATE_IDLE; - ftpc->len = 0; - ftpc->pos = 0; - goto quit; - } - - if (ftpc->state == FTPSTATE_LOGIN) { - ftpcmsg(ftpc, "503 Bad sequence of commands"); - } - else { - ftpc->state = FTPSTATE_IDLE; - ftpcmsg(ftpc, "503 Bad sequence of commands"); - } - -quit: - return 0; -} diff --git a/src/ftpdcwd.c b/src/ftpdcwd.c deleted file mode 100644 index 4b7698d..0000000 --- a/src/ftpdcwd.c +++ /dev/null @@ -1,374 +0,0 @@ -/* FTPDCWD.C */ -#include "httpd.h" -#include "cliblist.h" -#include "clibary.h" -#include "clibstr.h" -#include "osdcb.h" -#include "osjfcb.h" /* JFCB struct */ -#include "clibdscb.h" /* DSCB structs and prototypes */ - -static int cwd_error(FTPC *ftpc, char *p); -static int cwd_path(FTPC *ftpc, char *path); -static int cwd_hlq(FTPC *ftpc, char *hlq); -static int cwd_dsn(FTPC *ftpc, char *dsn); -static int cwd_dsnmem(FTPC *ftpc, char *dsnmem); - -int -ftpdcwd(FTPC *ftpc) -{ - int rc = 0; - char *p; - char buf[256]; - - buf[0] = 0; - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - - if (p) { - rc = ftpfqn(ftpc, p, buf); - switch (rc) { - default: - case FTPFQN_RC_PARMS: /* invalid parameters */ - case FTPFQN_RC_ERROR: /* Couldn't make sense of the input */ - rc = cwd_error(ftpc, p); - goto quit; - - case FTPFQN_RC_PATH: /* out is a path name */ - rc = cwd_path(ftpc, buf); - goto quit; - - case FTPFQN_RC_HLQ: /* out is a high level qualifier */ - rc = cwd_hlq(ftpc, buf); - goto quit; - - case FTPFQN_RC_DSN: /* out is a dataset name */ - rc = cwd_dsn(ftpc, buf); - goto quit; - - case FTPFQN_RC_DSNMEM: /* out is a dataset(member) name */ - rc = cwd_dsnmem(ftpc, buf); - goto quit; - } - } - - if (!p) { - ftpcmsg(ftpc, "550 Missing path or dataset name"); - } - else { - ftpcmsg(ftpc, "550 Invalid path name '%s'", p); - } - -quit: - return rc; -} - -static int cwd_error(FTPC *ftpc, char *p) -{ - ftpcmsg(ftpc, "550 Invalid path name '%s'", p); - - return 0; -} - -static int cwd_path(FTPC *ftpc, char *path) -{ - int rc = ufs_chgdir(ftpc->ufs, path); - - if (rc==0) { - ftpc->flags &= ~FTPC_FLAG_CWDDS; - ftpc->flags &= ~FTPC_FLAG_CWDPDS; - ftpcmsg(ftpc, "250 Working directory is '%s'", ftpc->ufs->cwd.path); - } - else { - ftpcmsg(ftpc, "550 Invalid path name '%s'", path); - } - - return rc; -} - -static int cwd_hlq(FTPC *ftpc, char *hlq) -{ - ACEE *acee = ftpc->acee; - int rc = 0; - int i; - unsigned count; - - i = strlen(hlq); - if (!i) { - ftpcmsg(ftpc, "550 Requested action not taken. Missing dataset name."); - goto quit; - } - - if (!acee) { - ftpcmsg(ftpc, "550 Requested action not taken. Login required."); - goto quit; - } - - rc = racf_auth(ftpc->acee, "DATASET", hlq, RACF_ATTR_READ); - if (rc > 4) { - ftpcmsg(ftpc, "550 Requested action not taken. READ Access DENIED rc=%d", rc); - goto quit; - } - - count = ftpc_ds_count(hlq, "NONVSAM", NULL); - if (!count) { - ftpcmsg(ftpc, "550 Requested action not taken. No Datasets."); - goto quit; - } - - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), hlq, 0); - ftpc->flags &= ~FTPC_FLAG_CWDPDS; - ftpc->flags |= FTPC_FLAG_CWDDS; - ftpcmsg(ftpc, "250 Dataset level is '%s'", ftpc->cwd); - -quit: - return rc; -} - -static int -cwd_dsn(FTPC *ftpc, char *dsn) -{ - ACEE *acee = ftpc->acee; - char *p = dsn; - int rc = 0; - FILE *fp = 0; - int i; - unsigned count; - - i = strlen(dsn); - if (!i) { - ftpcmsg(ftpc, "550 Requested action not taken. Missing dataset name."); - goto quit; - } - - if (dsn[0] != '.' && dsn[i-1]=='.') { - /* "some.dataset.level." -> "some.dataset.level" */ - i--; - dsn[i] = 0; - } - - if (!acee) { - ftpcmsg(ftpc, "550 Requested action not taken. Login required."); - goto quit; - } - - // wtof("%s: Userid:%*.*s", __func__, acee->aceeuser[0], acee->aceeuser[0], &acee->aceeuser[1]); - - /* check for access to this dataset name */ - rc = racf_auth(ftpc->acee, "DATASET", dsn, RACF_ATTR_READ); - - // wtof("%s: racf_auth(0x%06X, \"DATASET\", \"%s\", RACF_ATTR_READ) rc=%d", - // __func__, acee, dsn, rc); - - if (rc > 4) { - ftpcmsg(ftpc, "550 Requested action not taken. READ Access DENIED rc=%d", rc); - goto quit; - } - - /* can we open this dataset name? */ - fp = fopen(dsn, "r,record"); - if (fp) { - /* yes, is this dataset a PDS? */ - DCB *dcb = fp->dcb; - JFCB jfcb = {0}; - DSCB dscb = {0}; - DSCB1 *dscb1 = &dscb.dscb1; - - /* read the job file control block to get the volser */ - i = __rdjfcb(dcb, &jfcb); - if (i) goto level; - - /* get the DSCB for this dataset and volser */ - i = __dscbdv(fp->dataset, jfcb.jfcbvols, &dscb); - if (i) goto level; - - /* is this dataset as PDS? */ - if ((dscb1->dsorg1 & 0x7F) == DSGPO) { - /* yes, make this dataset the CWD */ - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), dsn, 0); - ftpc->flags &= ~FTPC_FLAG_CWDDS; - ftpc->flags |= FTPC_FLAG_CWDPDS; - ftpcmsg(ftpc, "250 PDS '%s' is current directory", ftpc->cwd); - goto quit; - } - } - -level: - count = ftpc_ds_count(dsn, "NONVSAM", NULL); - if (!count) { - ftpcmsg(ftpc, "550 Requested action not taken. No Datasets."); - goto quit; - } - - /* assume this is a dataset level */ - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), dsn, 0); - ftpc->flags &= ~FTPC_FLAG_CWDPDS; - ftpc->flags |= FTPC_FLAG_CWDDS; - ftpcmsg(ftpc, "250 Dataset level is '%s'", ftpc->cwd); - -quit: - if (fp) fclose(fp); - return rc; -} - -static int cwd_dsnmem(FTPC *ftpc, char *dsnmem) -{ - char *lparen = strchr(dsnmem, '('); - char *rparen = strchr(dsnmem, ')'); - - if (lparen && rparen) { - *lparen = '.'; - *rparen = 0; - return cwd_dsn(ftpc, dsnmem); - } - - ftpcmsg(ftpc, "550 Invalid dataset name '%s'", dsnmem); - - return 0; -} - -#if 0 -/* old code */ -int -ftpdcwd(FTPC *ftpc) -{ - int rc = 0; - FILE *fp = 0; - int i; - char *p; - char buf[256]; - - buf[0] = 0; - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - - if (!ftpc->ufs) goto do_dataset; - - if (p) { - if (p[0]=='/') goto do_path; /* CWD /some/path/name */ - if (p[0]=='\'') goto do_dataset; /* CWD 'some.dataset.name' */ - } - - if (ftpc->flags & FTPC_FLAG_CWDDS) goto do_dataset; - if (ftpc->flags & FTPC_FLAG_CWDPDS) goto do_dataset; - -do_path: - if (p) { - if (p[0]=='\'') { - /* skip quotes */ - while(*p=='\'') p++; - strtok(p, "\'"); - } - /* wtof("%s cwd=\"%s\"", __func__, ftpc->ufs->cwd.path); */ - rc = ufs_chgdir(ftpc->ufs, p); - /* wtof("%s ufs_chgdir(\"%s\"), rc=%d", __func__, p, rc); */ - if (rc==0) { - ftpc->flags &= ~FTPC_FLAG_CWDDS; - ftpc->flags &= ~FTPC_FLAG_CWDPDS; - ftpcmsg(ftpc, "250 Working directory is '%s'", ftpc->ufs->cwd.path); - } - else { - ftpcmsg(ftpc, "550 Invalid path name '%s'", p); - } - goto quit; - } - -do_dataset: - if (p) { - /* change dataset level? */ - if (strcmp(p, "..")==0) { - /* yes, do we have a '.' in the cwd? */ - p = strrchr(ftpc->cwd, '.'); - if (p) { - /* yes, truncate cwd at last period */ - *p = 0; - } - /* use cwd as buf */ - strcpy(buf, ftpc->cwd); - } - else { - /* skip quotes and periods */ - while(*p=='\'' || *p=='.') p++; - - /* copy to buf in upper case */ - for(i=0; i < sizeof(buf) && p[i] > ' ' && p[i] != '\''; i++) { - buf[i] = toupper(p[i]); - } - buf[i] = 0; - } - } - - /* remove any member name */ - strtok(buf, "()"); - - if (buf[0]=='/') { - strcpy(buf, &buf[1]); - p = strchr(buf,'/'); - if (p) *p = 0; - } - - i = strlen(buf); - if (!i) { - ftpcmsg(ftpc, "550 Missing dataset name"); - goto quit; - } - - if (buf[0] != '.' && buf[i-1]=='.') { - /* "some.dataset.level." -> "some.dataset.level" */ - i--; - buf[i] = 0; - } - - p = strrchr(buf, '/'); - if (p > buf) goto dir; - - p = strchr(buf, '.'); - if (!p) goto level; - - /* can we open this dataset name? */ - fp = fopen(buf, "r,record"); - if (fp) { - /* yes, is this dataset a PDS? */ - DCB *dcb = fp->dcb; - JFCB jfcb = {0}; - DSCB dscb = {0}; - DSCB1 *dscb1 = &dscb.dscb1; - - /* read the job file control block to get the volser */ - i = __rdjfcb(dcb, &jfcb); - if (i) goto level; - - /* get the DSCB for this dataset and volser */ - i = __dscbdv(fp->dataset, jfcb.jfcbvols, &dscb); - if (i) goto level; - - /* is this dataset as PDS? */ - if ((dscb1->dsorg1 & 0x7F) == DSGPO) { - /* yes, make this dataset the CWD */ - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), buf, 0); - ftpc->flags &= 0xFF - FTPC_FLAG_CWDDS; - ftpc->flags |= FTPC_FLAG_CWDPDS; - ftpcmsg(ftpc, "250 PDS '%s' is current directory", ftpc->cwd); - goto quit; - } - } - -level: - /* assume this is a dataset level */ - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), buf, 0); - ftpc->flags &= 0xFF - FTPC_FLAG_CWDPDS; - ftpc->flags |= FTPC_FLAG_CWDDS; - ftpcmsg(ftpc, "250 Dataset level is '%s'", ftpc->cwd); - goto quit; - -dir: - /* assume this is file system path */ - strcpyp(ftpc->cwd, sizeof(ftpc->cwd), buf, 0); - ftpc->flags &= 0xFF - FTPC_FLAG_CWDPDS; - ftpc->flags &= 0xFF - FTPC_FLAG_CWDDS; - ftpcmsg(ftpc, "250 Working directory is '%s'", ftpc->cwd); - -quit: - if (fp) fclose(fp); - return rc; -} -#endif /* old code */ diff --git a/src/ftpddele.c b/src/ftpddele.c deleted file mode 100644 index c9ccb2e..0000000 --- a/src/ftpddele.c +++ /dev/null @@ -1,164 +0,0 @@ -/* FTPDDELE.C */ -#include "httpd.h" - -static int isdataset(const char *name); -static int ismember(const char *name); - -__asm__("\n&FUNC SETC 'ftpddele'"); -int -ftpddele(FTPC *ftpc) -{ - int rc; - int dataset = 0; - int member = 0; - char *p; - char buf[256]; - - /* isolate the file/dataset/member name in the delete command */ - p = strtok(ftpc->cmd, " "); - if (!p) goto nope; - p = strtok(NULL, " "); - if (!p) goto nope; - -#if 1 - /* new code using ftpfqn() */ - rc = ftpfqn(ftpc, p, buf); - switch (rc) { - case FTPFQN_RC_PARMS: /* invalid parameters */ - case FTPFQN_RC_ERROR: /* Couldn't make sense of the input */ - goto nope; - - case FTPFQN_RC_PATH: /* buf is a path name */ - if (ftpc->ufs) { - /* must be UFS resource */ - rc = ufs_remove(ftpc->ufs, buf); - if (rc==0) goto okay; - } - goto nope; - - case FTPFQN_RC_HLQ: /* buf is a high level qualifier */ - goto nope; - - case FTPFQN_RC_DSN: /* buf is a dataset name */ - case FTPFQN_RC_DSNMEM: /* buf is a dataset(member) name */ - rc = remove(buf); /* try to delete the dataset asis */ - if (rc==0) goto okay; - goto nope; - - default: - goto nope; - } - -#else - /* old code - brute force */ - if (*p == '\'') { - char *e = strrchr(p+1,'\''); - - if (e) *e = 0; - - strcpy(p, p+1); - dataset = isdataset(p); - } - else if (ftpc->flags & FTPC_FLAG_CWDDS) { - sprintf(buf, "%s.%s", ftpc->cwd, p); - dataset = isdataset(buf); - if (dataset) p = buf; - } - else if (ftpc->flags & FTPC_FLAG_CWDPDS) { - member = ismember(p); - } - - /* if cwd is not a dataset OR this name looks like a dataset */ - if (dataset) { - rc = remove(p); /* try to delete the name asis */ - if (rc==0) goto okay; - } - - /* if the cwd is a PDS treat the name as a member of that PDS */ - if (member) { - sprintf(buf, "%s(%s)", ftpc->cwd, p); - rc = remove(buf); - if (rc==0) goto okay; - } - - /* otherwise, if we have a UFS, try to delete this file name */ - if (ftpc->ufs) { - /* must be UFS resource */ - rc = ufs_remove(ftpc->ufs, p); - if (rc==0) goto okay; - } -#endif - -nope: - ftpcmsg(ftpc, "550 Requested action not taken"); - goto quit; - -okay: - ftpcmsg(ftpc, "250 Requested file action okay, completed"); - -quit: - return 0; -} - -#if 0 /* old code */ -static int -isdataset(const char *name) -{ - int dataset = 0; - int qualifiers = 0; - char buf[256]; - char *p; - - if (name[0]=='\'') { - dataset=1; - goto quit; - } - - strcpy(buf, name); - for(p = strtok(buf, ".()"); p; p = strtok(NULL, ".()")) { - if (p[0]=='/') goto quit; /* not a dataset */ - if (strlen(p) > 8) goto quit; /* member or dataset level name too long */ - if (!ismember(p)) goto quit; /* bad character in name */ - qualifiers++; /* dataset name qualifiers */ - } - - if (qualifiers > 1) dataset=1; - -quit: - /* wtof("ftpddele->%s(\"%s\"): dataset=%d", __func__, name, dataset); */ - return dataset; -} - -static int -ismember(const char *name) -{ - int member = 0; - int len = strlen(name); - int i; - - if (len < 1) goto quit; /* invalid member name */ - - if (len <= 8) { - member = 1; /* assume the name is a valid member name */ - for(i=0; name[i]; i++) { - if (name[i]=='@') continue; - if (name[i]=='#') continue; - if (name[i]=='$') continue; - if (isalnum(name[i])) continue; - - /* not a valid character for a member name */ - member = 0; - break; - } - } - -quit: - return member; -} -#endif /* old code */ - -#if 0 -__asm__("STOW\tDCB,LIST,D\n" -"DCB\tDC\tF'0'\n" -"LIST\tDC\tF'0"); -#endif diff --git a/src/ftpdlist.c b/src/ftpdlist.c deleted file mode 100644 index 4a08740..0000000 --- a/src/ftpdlist.c +++ /dev/null @@ -1,12 +0,0 @@ -/* FTPDLIST.C */ -#include "httpd.h" -#include "cliblist.h" -#include "clibary.h" - -int -ftpdlist(FTPC *ftpc) -{ - /* use ftpslist() with brief set to false */ - return ftpslist(ftpc, 0); -} - diff --git a/src/ftpdmkd.c b/src/ftpdmkd.c deleted file mode 100644 index 6b92a88..0000000 --- a/src/ftpdmkd.c +++ /dev/null @@ -1,219 +0,0 @@ -/* FTPDMKD.C */ -#include "httpd.h" - -static int mkd_error(FTPC *ftpc, char *p); -static int mkd_path(FTPC *ftpc, char *path); -static int mkd_dsn(FTPC *ftpc, char *dsn); -static int mkd_dsnmem(FTPC *ftpc, char *dsnmem); - -int -ftpdmkd(FTPC *ftpc) -{ - int rc = 0; - char *p = 0; - char buf[256] = {0}; - - /* get parameters */ - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - - if (p) { - rc = ftpfqn(ftpc, p, buf); - switch (rc) { - default: - case FTPFQN_RC_PARMS: /* invalid parameters */ - case FTPFQN_RC_ERROR: /* Couldn't make sense of the input */ - rc = mkd_error(ftpc, p); - goto quit; - - case FTPFQN_RC_PATH: /* out is a path name */ - rc = mkd_path(ftpc, buf); - goto quit; - - case FTPFQN_RC_HLQ: /* out is a high level qualifier */ - case FTPFQN_RC_DSN: /* out is a dataset name */ - rc = mkd_dsn(ftpc, buf); - goto quit; - - case FTPFQN_RC_DSNMEM: /* out is a dataset(member) name */ - rc = mkd_dsnmem(ftpc, buf); - goto quit; - } - } - - if (!p) { - ftpcmsg(ftpc, "550 Missing path or dataset name"); - } - else { - ftpcmsg(ftpc, "550 Invalid path name '%s'", p); - } - -quit: - return rc; -} - -static int mkd_error(FTPC *ftpc, char *p) -{ - ftpcmsg(ftpc, "550 Invalid path name '%s'", p); - - return 0; -} - -static int mkd_path_tree(UFS *ufs, char *path) -{ - int rc = ufs_mkdir(ufs, path); - char *p; - - if (rc==ENOENT && path[0] == '/') { - p = strrchr(path+1, '/'); - if (p) { - *p = 0; - rc = mkd_path_tree(ufs, path); - *p = '/'; - - if (rc==EPERM) goto quit; - - rc = ufs_mkdir(ufs, path); - } - } - -quit: - return rc; -} - -static int mkd_path(FTPC *ftpc, char *path) -{ - int rc = 0; - - if (!ftpc->ufs) { - ftpcmsg(ftpc, "550 Unix File System is not available. Requested action not taken"); - goto quit; - } - - /* try to make the path */ - rc = mkd_path_tree(ftpc->ufs, path); - - if (rc) { - ftpcmsg(ftpc, "550-%s", strerror(rc)); - ftpcmsg(ftpc, "550 Requested action not taken"); - rc = 0; - } - else { - ftpcmsg(ftpc, "257 \"%s\" created", path); - } - -quit: - return rc; -} - -static int mkd_dsn(FTPC *ftpc, char *dsn) -{ - ACEE *acee = ftpc->acee; - char *p = dsn; - int rc = 0; - int i; - - i = strlen(dsn); - if (!i) { - ftpcmsg(ftpc, "550 Missing dataset name"); - goto quit; - } - - if (!acee) { - ftpcmsg(ftpc, "550 Login required for access to dataset '%s'", dsn); - goto quit; - } - - /* check for access to this dataset name */ - rc = racf_auth(ftpc->acee, "DATASET", dsn, RACF_ATTR_ALTER); - if (rc > 4) { - ftpcmsg(ftpc, "550 ALTER Access to dataset '%s' DENIED rc=%d", dsn, rc); - goto quit; - } - - /* we don't currently have code for allocating a new dataset "directory" */ - ftpcmsg(ftpc, "550 Unable to create a 'directory' dataset for '%s'", dsn); - -quit: - return rc; -} - -static int mkd_dsnmem(FTPC *ftpc, char *dsnmem) -{ - ftpcmsg(ftpc, "550 Invalid dataset name '%s'", dsnmem); - - return 0; -} - - -#if 0 -/* old code */ -int -ftpdmkd(FTPC *ftpc) -{ - int rc = 0; - int i = 0; - char *p = 0; - char buf[256] = {0}; - const char *cwd = ftpc->cwd; - - /* get parameters */ - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - - /* are we doing file system or dataset processing? */ - if (!ftpc->ufs) goto do_dataset; - if (ftpc->flags & FTPC_FLAG_CWDDS) goto do_dataset; - if (ftpc->flags & FTPC_FLAG_CWDPDS) goto do_dataset; - - /* file system it is */ - cwd = ftpc->ufs->cwd.path; - - if (p) { - /* skip quotes */ - while(*p=='\'') p++; - strtok(p, "\'"); - - rc = ufs_mkdir(ftpc->ufs, p); - if (rc) { - ftpcmsg(ftpc, "550-%s", strerror(rc)); - ftpcmsg(ftpc, "550 Requested action not taken"); - rc = 0; - } - else { - ftpcmsg(ftpc, "257 \"%s\" created", p); - } - goto quit; - } - -do_dataset: - if (p) { - /* skip quotes and periods */ - while(*p=='\'' || *p=='.') p++; - - /* copy to buf in upper case */ - for(i=0; i < sizeof(buf) && p[i] > ' ' && p[i] != '\''; i++) { - buf[i] = toupper(p[i]); - } - buf[i] = 0; - } - - if (strlen(buf)==0) { - ftpcmsg(ftpc, "501 Syntax error in parameters"); - goto quit; - } - - /* create directory */ - rc = EPERM; /* fail until we add some logic for dataset creation */ - - if (rc) { - ftpcmsg(ftpc, "550 Requested action not taken"); - goto quit; - } - - ftpcmsg(ftpc, "257 \"%s\" created", buf); - -quit: - return rc; -} -#endif /* old code */ diff --git a/src/ftpdnoop.c b/src/ftpdnoop.c deleted file mode 100644 index 4c76ca3..0000000 --- a/src/ftpdnoop.c +++ /dev/null @@ -1,10 +0,0 @@ -/* FTPDNOOP.C */ -#include "httpd.h" - -int -ftpdnoop(FTPC *ftpc) -{ - ftpcmsg(ftpc, "200 %-4.4s command okay", ftpc->cmd); - - return 0; -} diff --git a/src/ftpdpass.c b/src/ftpdpass.c deleted file mode 100644 index 8b60d7a..0000000 --- a/src/ftpdpass.c +++ /dev/null @@ -1,72 +0,0 @@ -/* FTPDPASS.C */ -#include "httpd.h" - -int -ftpdpass(FTPC *ftpc) -{ - int rc = 0; - char *p; - ACEE *acee; - - if (ftpc->state != FTPSTATE_LOGIN || !ftpc->cwd[0]) { - ftpcmsg(ftpc, "503 Bad sequence of commands"); - goto quit; - } - - if (ftpc->acee) { - /* release previous security invironment */ - racf_logout(&ftpc->acee); - ftpc->acee = 0; - } - - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - if (!p) goto reset; - - /* login user */ - acee = racf_login(ftpc->cwd, p, 0, &rc); - if (!acee) { - wtof("HTTPD201E Invalid login attempt for userid '%s'", ftpc->cwd); - goto reset; - } - - /* login success */ - wtof("HTTPD200I FTP login by user '%s' success", ftpc->cwd); - ftpc->acee = acee; - - /* set state to IDLE */ - ftpc->state = FTPSTATE_IDLE; - - ftpc->flags = 0; - - if (ftpc->ufs) { - char group[9]; - /* wtof("%s setting acee %08X", __func__, ftpc->acee); */ - ufs_set_acee(ftpc->ufs, ftpc->acee); - memcpyp(group, sizeof(group), - &acee->aceegrp[1], acee->aceegrp[0], 0); - ufs_setuser(ftpc->ufs, ftpc->cwd, group); - /* try to change dir to user name */ - /* wtof("%s ufs_chgdir(%s)", __func__, ftpc->cwd); */ - if (ufs_chgdir(ftpc->ufs, ftpc->cwd)!=0) { - /* that didn't work, so CD to root */ - /* wtof("%s ufs_chgdir(%s)", __func__, "/"); */ - ufs_chgdir(ftpc->ufs, "/"); /* CD to root "/" */ - } - } - else { - /* wtof("%s No ftpc->ufs handle", __func__); */ - ftpc->flags |= FTPC_FLAG_CWDDS; /* dataset level */ - } - - ftpcmsg(ftpc, "230 User logged in, proceed"); - goto quit; - -reset: - ftpc->state = FTPSTATE_LOGIN; - ftpc->cwd[0] = 0; - ftpcmsg(ftpc, "530 Not logged in"); - -quit: - return 0; -} diff --git a/src/ftpdpasv.c b/src/ftpdpasv.c deleted file mode 100644 index d84241a..0000000 --- a/src/ftpdpasv.c +++ /dev/null @@ -1,82 +0,0 @@ -/* FTPDPASV.C */ -#include "httpd.h" - -int -ftpdpasv(FTPC *ftpc) -{ - int rc = 0; - int len = 0; - struct sockaddr_in in = {0}; - unsigned char *a; - unsigned char *p; - -#if 0 /* old method was to bind localhost for the data listener socket */ - in.sin_family = AF_INET; - in.sin_addr.s_addr = 0x7F000001; /* 127.0.0.1 */ - /* note we're not setting a port as we want the system to assign a port */ -#else - /* The client has requested PASV which means he wants us to open a listening port - * on this server for the data connection. So we will use the client socket to - * obtain the servers host address as we want to bind the data socket to the - * same host address. - */ - len = sizeof(in); - if (getsockname(ftpc->client_socket, (void *)&in, &len) < 0) { - ftpcmsg(ftpc, "500 Unable to get client socket name"); - goto failed; - } - /* we clear the port number so that the host will assign an unused port - * for the data connection when we bind the new socket. - */ - in.sin_port = 0; -#endif - - /* wtof("%s socket(%d,%d,%d)", __func__, AF_INET, SOCK_STREAM, IPPROTO_TCP); */ - ftpc->data_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (ftpc->data_socket < 0) { - ftpcmsg(ftpc, "500 Unable to allocate passive data socket"); - goto failed; - } - - /* wtof("%s socket=%d", __func__, ftpc->data_socket); */ - rc = bind(ftpc->data_socket, &in, sizeof(in)); - if (rc < 0) { - wtof("%s bind failed for socket=%d, rc=%d, errno=%d", __func__, ftpc->data_socket, rc, errno); - ftpcmsg(ftpc, "500 Unable to bind data socket"); - goto failed; - } - - /* get socket address and port */ - len = sizeof(in); - if (getsockname(ftpc->data_socket, (void *)&in, &len) < 0) { - ftpcmsg(ftpc, "500 Unable to get data socket name"); - goto failed; - } - - /* listen on the data socket */ - if (listen(ftpc->data_socket, 1) < 0) { - ftpcmsg(ftpc, "500 Unable to listen on data socket"); - goto failed; - } - - /* save socket address and port */ - ftpc->data_addr = in.sin_addr.s_addr; - ftpc->data_port = in.sin_port; - ftpc->flags |= FTPC_FLAG_PASSIVE; - - a = (unsigned char*)&ftpc->data_addr; - p = (unsigned char*)&ftpc->data_port; - ftpcmsg(ftpc, "227 Entering Passive Mode (%u,%u,%u,%u,%u,%u)", - a[0], a[1], a[2], a[3], p[2], p[3]); - goto quit; - -failed: - if (ftpc->data_socket >= 0) { - closesocket(ftpc->data_socket); - } - ftpc->data_socket = -1; - ftpc->flags &= 0xFF - FTPC_FLAG_PASSIVE; - -quit: - return 0; -} diff --git a/src/ftpdpc.c b/src/ftpdpc.c deleted file mode 100644 index 8a07c9e..0000000 --- a/src/ftpdpc.c +++ /dev/null @@ -1,205 +0,0 @@ -/* FTPDPC.C -** Process client -*/ -#include "httpd.h" - -typedef struct { - char *word; /* keyword name */ - int len; /* keyword length */ - int (*func)(FTPC *ftpc); /* function pointer */ -} FTP_CMDS; - -static FTP_CMDS login_cmds[] = { - {"noop", 4, ftpdnoop}, /* No operation--send positive reply */ - {"pass", 4, ftpdpass}, /* PASS xxxxxxxx */ - {"quit", 4, ftpdquit}, /* Quit */ - {"user", 4, ftpduser}, /* USER xxxxxxxx */ -}; -#define MAX_LOGIN_CMDS (sizeof(login_cmds) / sizeof(FTP_CMDS)) - -static FTP_CMDS cmds[] = { - {"abor", 4, ftpdabor}, /* Abort current operation */ -#if 0 - {"acct", 4, ftpdacct}, /* ACCT xxxxxxxx */ - {"allo", 4, ftpdallo}, /* Allocate space for file */ - {"appe", 4, ftpdappe}, /* Append xxxxxxx with data -- UPLOAD APPEND */ - {"cdup", 4, ftpdcdup}, /* Change Working Directory to parent */ -#endif - {"cwd", 3, ftpdcwd}, /* Change Working Directory xxxxxxxx */ - {"dele", 4, ftpddele}, /* Delete xxxxxxx from file system */ -#if 0 - {"help", 4, ftpdhelp}, /* Print help text */ -#endif - {"list", 4, ftpdlist}, /* Directory List via data connection */ - {"mkd", 3, ftpdmkd}, /* Make Directory */ -#if 0 - {"mode", 4, ftpdmode}, /* Mode {s,b,c} -- STREAM, BLOCK, COMPRESSED */ - {"nlst", 4, ftpdnlst}, /* Name List via data connection */ -#endif - {"noop", 4, ftpdnoop}, /* No operation--send positive reply */ - {"opts", 4, 0 }, /* valid command, but we don't implement it */ - {"pass", 4, ftpdpass}, /* PASS xxxxxxxx */ - {"pasv", 4, ftpdpasv}, /* Returns port of server for data transfer */ - {"port", 4, ftpdport}, /* Port h1,h2,h3,h4,p1,p2 of client for data */ - {"pwd", 3, ftpdpwd}, /* Print name of current working directory */ - {"quit", 4, ftpdquit}, /* Quit */ -#if 0 - {"rein", 4, ftpdrein}, /* Reinitialize */ -#endif - {"retr", 4, ftpdretr}, /* Retrieve xxxxxxxx -- DOWNLOAD filename */ - {"rmd", 3, ftpdrmd}, /* Remove Directory */ -#if 0 - {"rnfr", 4, ftpdrnfr}, /* Rename from xxxxxxxx */ - {"rnft", 4, ftpdrnft}, /* Rename to xxxxxxxx */ - {"site", 4, ftpdsite}, /* Site specific options */ - {"smnt", 4, ftpdsmnt}, /* Structure Mount--mount different file system */ - {"stat", 4, ftpdstat}, /* Print FTP server information */ -#endif - {"stor", 4, ftpdstor}, /* Store xxxxxxxx in file system -- UPLOAD */ -#if 0 - {"stou", 4, ftpdstou}, /* Store unique -- Server chooses filename */ - {"stru", 4, ftpdstru}, /* Structure {f,r,p} -- FILE, RECORD, PAGE */ -#endif - {"syst", 4, ftpdsyst}, /* Print operating system type */ - {"type", 4, ftpdtype}, /* Type {a,e,i,l} -- ASCII, EBCDIC, IMAGE, LOCAL*/ - {"user", 4, ftpduser}, /* USER xxxxxxxx */ - /* synonyms for the 3 letter versions of these commands */ - {"xmkd", 4, ftpdmkd}, /* Make Directory */ - {"xpwd", 4, ftpdpwd}, /* Print name of current working directory */ - {"xrmd", 4, ftpdrmd}, /* Remove Directory */ -}; -#define MAX_CMDS (sizeof(cmds) / sizeof(FTP_CMDS)) - -static int find(const void *key, const void *item); - -int ftpd_process_client(FTPC *ftpc) -{ - int rc = 0; - int len = strlen(ftpc->cmd); - FTPD *ftpd = ftpc->ftpd; - char *ptr; - FTP_CMDS *cmd; -#if 0 - wtof("Enter %s", __func__); - wto_traceback(NULL); -#endif - if (!ftpc) goto quit; - - switch(ftpc->state) { - case FTPSTATE_INITIAL: - /* the FTP client just connected to us, so send a welcome and wait for commands */ - ftpcmsg(ftpc, "220-Welcome to the HTTPD FTP server on port %d", ftpc->ftpd->port); - ftpcmsg(ftpc, "220 Anonymous login allowed. Login is required."); - if (ftpd->sys) { - /* initialize for Unix File System access */ - if (ftpc->ufs) ufsfree(&ftpc->ufs); - ftpc->ufs = ufsnew(); - } - ftpc->state = FTPSTATE_LOGIN; - break; - - case FTPSTATE_LOGIN: - ptr = ftpcgets(ftpc); - if (!ptr) { - /* wtof("%s client connection terminated", __func__); */ - ftpc->state = FTPSTATE_TERMINATE; - break; - } - - /* look for valid command */ - cmd = bsearch(ftpc->cmd, login_cmds, MAX_LOGIN_CMDS, sizeof(FTP_CMDS), find); - if (!cmd) { - /* command not found */ - if (len > 20) strcpy(&ftpc->cmd[20], "..."); - ftpcmsg(ftpc, "500 Syntax error, command \"%s\" not recognized", ftpc->cmd); - break; /* not fatal, we'll get called again to process the next command */ - } - - /* command found */ - rc = cmd->func(ftpc); - break; - - case FTPSTATE_IDLE: - ptr = ftpcgets(ftpc); - if (!ptr) { - /* wtof("%s client connection terminated", __func__); */ - ftpc->state = FTPSTATE_TERMINATE; - break; - } - - /* look for valid command */ - cmd = bsearch(ftpc->cmd, cmds, MAX_CMDS, sizeof(FTP_CMDS), find); - if (!cmd) { - /* command not found */ - if (len > 20) strcpy(&ftpc->cmd[20], "..."); - ftpcmsg(ftpc, "500 Syntax error, command \"%s\" not recognized", ftpc->cmd); - break; /* not fatal, we'll get called again to process the next command */ - } - - /* command found */ - if (ftpc->cmd[cmd->len]!=' ' && ftpc->cmd[cmd->len]!=0) { - /* only a partial match */ - if (len > 20) strcpy(&ftpc->cmd[20], "..."); - ftpcmsg(ftpc, "500 Syntax error, command \"%s\" not recognized", ftpc->cmd); - break; /* not fatal, we'll get called again to process the next command */ - } - - if (!cmd->func) { - ftpcmsg(ftpc, "502 Command not implemented"); - break; - } - - /* call the command function */ - rc = cmd->func(ftpc); - - /* sync file system buffers to disk */ - if (ftpc->ufs) ufs_sync(ftpc->ufs); - break; - - case FTPSTATE_TRANSFER: - if (ftpc->flags & FTPC_FLAG_SEND) { - ftpcsend(ftpc); - } - else if (ftpc->flags & FTPC_FLAG_RECV) { - ftpcrecv(ftpc); - } - else { - /* abort transfer */ - ftpdabor(ftpc); - ftpc->state = FTPSTATE_IDLE; - } - break; - - case FTPSTATE_TERMINATE: - if (ftpd->sys) { - if (ftpc->ufs) { - /* sync file system buffers to disk */ - ufs_sync(ftpc->ufs); - - /* terminate Unix File System access */ - ufsfree(&ftpc->ufs); - } - } - break; - } - - -quit: -#if 0 - wtof("Exit %s", __func__); -#endif - return rc; -} - -static int -find(const void *vitem, const void *vkey) -{ - FTP_CMDS *item = (FTP_CMDS *)vitem; - char *key = (char *)vkey; -#if 0 - wtodumpf(key, 16, "key"); - wtodumpf(item->word, item->len, "item->word"); -#endif - /* compare key with keyword ignoring case */ - return(strncmpi(item->word, key, item->len)); -} diff --git a/src/ftpdpcs.c b/src/ftpdpcs.c deleted file mode 100644 index a64d690..0000000 --- a/src/ftpdpcs.c +++ /dev/null @@ -1,39 +0,0 @@ -/* FTPDPCS.C -** Process FTPD clients -*/ -#include "httpd.h" - -__asm__("\n&FUNC SETC 'ftpd_process_clients'"); -int ftpd_process_clients(void) -{ - CLIBGRT *grt = __grtget(); - HTTPD *httpd = grt->grtapp1; - FTPD *ftpd = httpd->ftpd; - int lockrc; - unsigned count; - unsigned n; - FTPC *ftpc; - - if (!ftpd) goto quit; - if (!ftpd->ftpc) goto quit; /* no clients */ - - lockrc = lock(&ftpd, 0); - if (lockrc==0) goto locked; /* we have the lock */ - if (lockrc==8) goto locked; /* we already had the lock */ - wtof("%s lock failed", __func__); - goto quit; - -locked: - count = array_count(&ftpd->ftpc); - for(n=0; n < count; n++) { - ftpc = ftpd->ftpc[n]; - if (!ftpc) continue; /* no client handle? */ - - ftpd_process_client(ftpc); - } - - if (lockrc==0) unlock(&ftpd, 0); - -quit: - return 0; -} diff --git a/src/ftpdport.c b/src/ftpdport.c deleted file mode 100644 index 7212b98..0000000 --- a/src/ftpdport.c +++ /dev/null @@ -1,73 +0,0 @@ -/* FTPDPORT.C */ -#include "httpd.h" - -int -ftpdport(FTPC *ftpc) -{ - unsigned addr = 0; - unsigned port = 0; - char *p; - - if (ftpc->state == FTPSTATE_INITIAL || ftpc->state == FTPSTATE_LOGIN) { - ftpcmsg(ftpc, "530 Not logged in"); - goto quit; - } - - /* parse "PORT h1,h2,h3,h4,p1,p2" */ - - p = strtok(ftpc->cmd, " "); /* "PORT" */ - if (p) p = strtok(NULL, " "); /* "h1,h2,h3,h4,p1,p2" */ - if (p) p = strtok(p, ","); /* "h1" */ - if (p) { - /* "h1" */ - addr = atoi(p); - p = strtok(NULL, ","); /* "h2" */ - } - if (p) { - /* "h2" */ - addr = addr << 8; - addr += atoi(p); - p = strtok(NULL, ","); /* "h3" */ - } - if (p) { - /* "h3" */ - addr = addr << 8; - addr += atoi(p); - p = strtok(NULL, ","); /* "h4" */ - } - if (p) { - /* "h4" */ - addr = addr << 8; - addr += atoi(p); - p = strtok(NULL, ","); /* "p1" */ - } - if (p) { - /* "p1" */ - port = atoi(p); - p = strtok(NULL, ","); /* "p2" */ - } - if (p) { - /* "p2" */ - port = port << 8; - port += atoi(p); - } - - if (addr == 0 || port == 0) { - ftpcmsg(ftpc, "501 Syntax error in parameters"); - goto quit; - } - - ftpc->data_addr = addr; - ftpc->data_port = port; - if (ftpc->data_socket >= 0) { - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - } - ftpc->flags &= 0xFF - FTPC_FLAG_PASSIVE; - - ftpcmsg(ftpc,"200 PORT command okay"); - -quit: - return 0; -} - diff --git a/src/ftpdpwd.c b/src/ftpdpwd.c deleted file mode 100644 index 48c0803..0000000 --- a/src/ftpdpwd.c +++ /dev/null @@ -1,20 +0,0 @@ -/* FTPDPWD.C */ -#include "httpd.h" - -int -ftpdpwd(FTPC *ftpc) -{ - const char *cwd = ftpc->cwd; - - if (!ftpc->ufs) goto do_send; - if (ftpc->flags & FTPC_FLAG_CWDDS) goto do_send; - if (ftpc->flags & FTPC_FLAG_CWDPDS) goto do_send; - - cwd = ftpc->ufs->cwd.path; - -do_send: - ftpcmsg(ftpc, "257 \"%s\" current directory", cwd); - -quit: - return 0; -} diff --git a/src/ftpdquit.c b/src/ftpdquit.c deleted file mode 100644 index 93e64d4..0000000 --- a/src/ftpdquit.c +++ /dev/null @@ -1,14 +0,0 @@ -/* FTPDQUIT.C */ -#include "httpd.h" - -int -ftpdquit(FTPC *ftpc) -{ - if (ftpc->state == FTPSTATE_TRANSFER) { - ftpdabor(ftpc); - } - - ftpc->state = FTPSTATE_TERMINATE; - - return 0; -} diff --git a/src/ftpdretr.c b/src/ftpdretr.c deleted file mode 100644 index 184b882..0000000 --- a/src/ftpdretr.c +++ /dev/null @@ -1,172 +0,0 @@ -/* FTPDRETR.C */ -#include "ftpd.h" - -static int retr_error(FTPC *ftpc, char *fn); -static int retr_begin(FTPC *ftpc, char *fqn, int fqnrc); - -int -ftpdretr(FTPC *ftpc) -{ - int rc = 0; - char *fn; - char fqn[256]; - - fn = strtok(ftpc->cmd, " "); - if (fn) fn = strtok(NULL, " "); - if (!fn) { - ftpcmsg(ftpc, "501 missing file name"); - goto quit; - } - - /* transform fn to fully qualifed name */ - rc = ftpfqn(ftpc, fn, fqn); - - /* process the request */ - switch (rc) { - default: - case FTPFQN_RC_PARMS: /* invalid parameters */ - case FTPFQN_RC_ERROR: /* Couldn't make sense of the input */ - rc = retr_error(ftpc, fn); - goto quit; - - case FTPFQN_RC_PATH: /* fqn is a path name */ - case FTPFQN_RC_HLQ: /* fqn is a high level qualifier */ - case FTPFQN_RC_DSN: /* fqn is a dataset name */ - case FTPFQN_RC_DSNMEM: /* fqn is a dataset(member) name */ - rc = retr_begin(ftpc, fqn, rc); - goto quit; - } - -quit: - return rc; -} - -static int -retr_begin(FTPC *ftpc, char *fqn, int fqnrc) -{ - FILE *fp = 0; - char *fm; - int rc; - - if (ftpc->acee && (fqnrc != FTPFQN_RC_PATH)) { - /* we have an acee and this a MVS dataset name */ - rc = racf_auth(ftpc->acee, "DATASET", fqn, RACHECK_ATTR_READ); - if (rc > 4) { - ftpcmsg(ftpc, "550-READ access to '%s' DENIED rc=%d", fqn, rc); - ftpcmsg(ftpc, "550 Requested file action aborted"); - return 0; - } - } - - if (ftpc->type==FTPC_TYPE_ASCII || ftpc->type==FTPC_TYPE_EBCDIC) { - fm = "r"; - } - else { - fm = "rb"; - } - - fp = ftpfopen(ftpc, fqn, fm, fqnrc); - if (!fp) { - ftpcmsg(ftpc, "550 open of \"%s\" failed", fqn); - return 0; - } - - ftpc->fp = fp; /* this file handle */ - ftpc->flags |= FTPC_FLAG_SEND; /* data is out bound */ - ftpc->flags &= ~FTPC_FLAG_RECV; /* not receiving data */ - ftpc->len = 0; /* buffer is empty */ - ftpc->pos = 0; /* buffer is empty */ - return ftpcsend(ftpc); -} - -static int -retr_error(FTPC *ftpc, char *fn) -{ - ftpcmsg(ftpc, "550 invalid file name \"%s\"", fn); - return 0; -} - - -#if 0 -/* old code */ -int -ftpdretr(FTPC *ftpc) -{ - FILE *fp = 0; - char *fn; - int i; - int bin; - char dataset[56] = ""; - - fn = strtok(ftpc->cmd, " "); - if (fn) fn = strtok(NULL, " "); - if (!fn) { - ftpcmsg(ftpc, "501 missing file name"); - goto quit; - } - - if ((ftpc->flags & FTPC_FLAG_CWDDS) || (ftpc->flags & FTPC_FLAG_CWDPDS)) { - /* cwd is dataset level or pds */ - if (ftpc->flags & FTPC_FLAG_CWDPDS) { - /* pds, so make full dataset name with member */ - if (strlen(fn) > 8) { - ftpcmsg(ftpc, "501 CWD is PDS and requested member name is too long"); - goto quit; - } - snprintf(dataset, sizeof(dataset)-1, "%s(%s)", ftpc->cwd, fn); - } - else if (ftpc->flags & FTPC_FLAG_CWDDS) { - strcpyp(dataset, sizeof(dataset)-1, fn, 0); - } - dataset[sizeof(dataset)-1] = 0; - fn = dataset; - - /* make dataset name upper case */ - for(i=0; fn[i]; i++) { - fn[i] = toupper(fn[i]); - } - - if (ftpc->type==FTPC_TYPE_ASCII || ftpc->type==FTPC_TYPE_EBCDIC) { - bin = 0; - } - else { - bin = 1; - } - fp = ftpfopen(ftpc, fn, bin ? "rb" :"r"); - - if (!fp) { - ftpcmsg(ftpc, "550 open of \"%s\" failed", fn); - goto quit; - } - - ftpc->fp = fp; /* this file handle */ - ftpc->flags |= FTPC_FLAG_SEND; /* data is out bound */ - ftpc->flags &= 0xFF - FTPC_FLAG_RECV; /* not receiving data */ - ftpc->len = 0; /* buffer is empty */ - ftpc->pos = 0; /* buffer is empty */ - return ftpcsend(ftpc); - } - - /* must be UFS resource */ - if (ftpc->type==FTPC_TYPE_ASCII || ftpc->type==FTPC_TYPE_EBCDIC) { - bin = 0; - } - else { - bin = 1; - } - ftpc->fp = ftpfopen(ftpc, fn, bin ? "rb" : "r"); - if (!ftpc->fp) { - ftpcmsg(ftpc, "550 open of \"%s\" failed", fn); - goto quit; - } - - ftpc->flags |= FTPC_FLAG_SEND; /* data is out bound */ - ftpc->flags &= 0xFF - FTPC_FLAG_RECV; /* not receiving data */ - ftpc->len = 0; /* buffer is empty */ - ftpc->pos = 0; /* buffer is empty */ - return ftpcsend(ftpc); - -quit: - return 0; -} -#endif /* old-code */ diff --git a/src/ftpdrmd.c b/src/ftpdrmd.c deleted file mode 100644 index 81740bc..0000000 --- a/src/ftpdrmd.c +++ /dev/null @@ -1,59 +0,0 @@ -/* FTPDRMD.C */ -#include "httpd.h" - -int -ftpdrmd(FTPC *ftpc) -{ - int rc = 0; - int i = 0; - char *p = 0; - char buf[256] = {0}; - const char *cwd = ftpc->cwd; - - /* get parameters */ - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - - /* are we doing file system or dataset processing? */ - if (!ftpc->ufs) goto do_dataset; - if (ftpc->flags & FTPC_FLAG_CWDDS) goto do_dataset; - if (ftpc->flags & FTPC_FLAG_CWDPDS) goto do_dataset; - - /* file system it is */ - cwd = ftpc->ufs->cwd.path; - - if (p) { - /* skip quotes */ - while(*p=='\'') p++; - strtok(p, "\'"); - - rc = ufs_rmdir(ftpc->ufs, p); - if (rc) { - ftpcmsg(ftpc, "550-%s", strerror(rc)); - ftpcmsg(ftpc, "550 Requested action not taken"); - rc = 0; - } - else { - ftpcmsg(ftpc, "250 directory \"%s\" removed", p); - } - goto quit; - } - -do_dataset: - if (!p) { - ftpcmsg(ftpc, "501 Syntax error in parameters"); - goto quit; - } - - /* we'll add a call to remove() at some point, but for now we'll - ** disallow any deletes just to be a little bit safer. - */ -#if 1 - ftpcmsg(ftpc, "550 Requested action not taken"); -#else - ftpcmsg(ftpc, "250 directory removed"); -#endif - -quit: - return 0; -} diff --git a/src/ftpdsecs.c b/src/ftpdsecs.c deleted file mode 100644 index e3a15b7..0000000 --- a/src/ftpdsecs.c +++ /dev/null @@ -1,36 +0,0 @@ -/* FTPDSECS.C */ -#include "httpd.h" - -double * -ftpdsecs(double *secs) -{ - U64 tod; - struct timeval tv; - double tmp; - - if (!secs) secs = &tmp; - - /* get STCK value */ - __asm__("STCK\t0(%0)" : : "r" (&tod)); - - /* make Jan 1 1900 (STCK) relative to Jan 1 1970 (unix epoch) */ - tod -= 0x7D91048BCA000000ULL; /* STCK value for Jan 1 1970 */ - - /* convert to microseconds (bits 0-51==number of microseconds) */ - tod >>= 12; /* convert to microseconds (1 us = .000001 sec) */ - - /* calc seconds and microseconds (divide by 1000000) */ - __asm__( - "LM\t0,1,0(%0) load TOD microseconds\n\t" - "D\t0,=F'1000000' divide by 1000000\n\t" - "ST\t1,0(0,%1) store seconds (quotient)\n\t" - "ST\t0,4(0,%1) store microseconds (remainder)" - : : "r" (&tod), "r" (&tv)); - - /* Scale the microseconds and add to our result (secs.usecs) */ - *secs = ((double)tv.tv_sec + ((double)tv.tv_usec / 1000000.0)); - -quit: - return secs; -} - diff --git a/src/ftpdstor.c b/src/ftpdstor.c deleted file mode 100644 index c0a51ec..0000000 --- a/src/ftpdstor.c +++ /dev/null @@ -1,85 +0,0 @@ -/* FTPDSTOR.C */ -#include "httpd.h" - -static int stor_error(FTPC *ftpc, char *fn); -static int stor_begin(FTPC *ftpc, char *fqn, int fqnrc); - -int -ftpdstor(FTPC *ftpc) -{ - int rc = 0; - char *fn; - char *fm; - char fqn[256]; - - fn = strtok(ftpc->cmd, " "); - if (fn) fn = strtok(NULL, ""); - if (!fn) { - ftpcmsg(ftpc, "500 Syntax error, missing file name"); - goto quit; - } - - rc = ftpfqn(ftpc, fn, fqn); - switch (rc) { - default: - case FTPFQN_RC_PARMS: /* invalid parameters */ - case FTPFQN_RC_ERROR: /* Couldn't make sense of the input */ - rc = stor_error(ftpc, fn); - goto quit; - - case FTPFQN_RC_PATH: /* fqn is a path name */ - case FTPFQN_RC_HLQ: /* fqn is a high level qualifier */ - case FTPFQN_RC_DSN: /* fqn is a dataset name */ - case FTPFQN_RC_DSNMEM: /* fqn is a dataset(member) name */ - rc = stor_begin(ftpc, fqn, rc); - goto quit; - } - -quit: - return rc; -} - -static int -stor_begin(FTPC *ftpc, char *fqn, int fqnrc) -{ - char *fm; - int rc; - - if (ftpc->acee && (fqnrc != FTPFQN_RC_PATH)) { - /* we have an acee and this a MVS dataset name */ - rc = racf_auth(ftpc->acee, "DATASET", fqn, RACHECK_ATTR_UPDATE); - if (rc > 4) { - ftpcmsg(ftpc, "552-UPDATE access to '%s' DENIED rc=%d", fqn, rc); - ftpcmsg(ftpc, "552 Requested file action aborted"); - return 0; - } - } - - if (ftpc->type == FTPC_TYPE_ASCII || ftpc->type == FTPC_TYPE_EBCDIC) { - fm = "w"; - } - else { - fm = "wb"; - } - - ftpc->fp = ftpfopen(ftpc, fqn, fm, fqnrc); - if (!ftpc->fp) { - ftpcmsg(ftpc, "552-Open of \"%s\" failed", fqn); - ftpcmsg(ftpc, "552 Requested file action aborted"); - goto quit; - } - - ftpc->flags |= FTPC_FLAG_RECV; /* data is in bound */ - ftpc->flags &= ~FTPC_FLAG_SEND; - return ftpcrecv(ftpc); - -quit: - return 0; -} - -static int -stor_error(FTPC *ftpc, char *fn) -{ - ftpcmsg(ftpc, "550 invalid file name \"%s\"", fn); - return 0; -} diff --git a/src/ftpdsyst.c b/src/ftpdsyst.c deleted file mode 100644 index ad011c3..0000000 --- a/src/ftpdsyst.c +++ /dev/null @@ -1,9 +0,0 @@ -/* FTPDSYST.C */ -#include "httpd.h" - -int -ftpdsyst(FTPC *ftpc) -{ - ftpcmsg(ftpc, "215 UNIX Type: L8"); - return 0; -} diff --git a/src/ftpdterm.c b/src/ftpdterm.c deleted file mode 100644 index ddf83de..0000000 --- a/src/ftpdterm.c +++ /dev/null @@ -1,76 +0,0 @@ -/* FTPDTERM.C */ -#include "httpd.h" - -void -ftpdterm(FTPD **ppftpd) -{ - FTPD *ftpd; - FTPC *ftpc; - int i; - unsigned n; - unsigned count; - - if (!ppftpd) goto quit; - ftpd = *ppftpd; - if (!ftpd) goto quit; - - ftpd->flags |= FTPD_FLAG_QUIESCE; - ftpd->flags |= FTPD_FLAG_SHUTDOWN; - - if (ftpd->ftpd_thread) { - CTHDTASK *task = ftpd->ftpd_thread; - - for(i=0; (i < 10) && (!(task->termecb & 0x40000000)); i++) { - if (i) { - wtof("FTPD040I Waiting for FTPD thread to terminate (%d)\n", - i); - } - /* we need to wait 1 second */ - __asm__("STIMER WAIT,BINTVL==F'100' 1 seconds"); - } - - if(!(task->termecb & 0x40000000)) { - wtof("FTPD041I Force detaching FTPD thread\n"); - } - cthread_delete(&ftpd->ftpd_thread); - ftpd->ftpd_thread = 0; - } - - if (ftpd->ftpc) { - /* terminate all clients */ - count = array_count(&ftpd->ftpc); - for(n=0; n < count; n++) { - ftpc = ftpd->ftpc[n]; - if (!ftpc) continue; - ftpcterm(&ftpc); - ftpd->ftpc[n] = 0; - } - array_free(&ftpd->ftpc); - ftpd->ftpc = 0; - } - - if (ftpd->listen >= 0) { - /* close listener socket */ - closesocket(ftpd->listen); - ftpd->listen = -1; - } - - if (ftpd->stats) { - /* close statistics file */ - fclose(ftpd->stats); - ftpd->stats = 0; - } - if (ftpd->dbg) { - /* close debug file */ - fclose(ftpd->dbg); - ftpd->dbg = 0; - } - - /* free the FTPD handle */ - free(ftpd); - *ppftpd = 0; - -quit: - return; -} - diff --git a/src/ftpdtype.c b/src/ftpdtype.c deleted file mode 100644 index a200dab..0000000 --- a/src/ftpdtype.c +++ /dev/null @@ -1,39 +0,0 @@ -/* FTPDTYPE.C */ -#include "httpd.h" - -int -ftpdtype(FTPC *ftpc) -{ - char *p; - - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, ""); - - switch(p ? *p : 0) { - case 'a': - case 'A': - ftpc->type = FTPC_TYPE_ASCII; - goto okay; - case 'e': - case 'E': - ftpc->type = FTPC_TYPE_EBCDIC; - goto okay; - case 'i': - case 'I': - ftpc->type = FTPC_TYPE_IMAGE; - goto okay; - case 'l': - case 'L': - ftpc->type = FTPC_TYPE_LOCAL; - goto okay; - default: - ftpcmsg(ftpc, "501 Syntax error in parameters"); - goto quit; - } - -okay: - ftpcmsg(ftpc, "200 TYPE command okay"); - -quit: - return 0; -} diff --git a/src/ftpduser.c b/src/ftpduser.c deleted file mode 100644 index 7e622b4..0000000 --- a/src/ftpduser.c +++ /dev/null @@ -1,53 +0,0 @@ -/* FTPDUSER.C */ -#include "httpd.h" - -int -ftpduser(FTPC *ftpc) -{ - int len = 0; - char *p; - - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, ""); - - if (p) len = strlen(p); - if (len < 1 || len > 8) { - if (p && strncmpi("anonymous", p, 9)==0) { - wtof("HTTPD200I user 'anonymous' logged into FTP"); - if (ftpc->acee) { - /* release previous security invironment */ - racf_logout(&ftpc->acee); - ftpc->acee = 0; - } - ftpcmsg(ftpc, "230 User logged in, proceed"); - ftpc->state = FTPSTATE_IDLE; - ftpc->flags &= ~FTPC_FLAG_CWDPDS; - ftpc->flags &= ~FTPC_FLAG_CWDDS; - if (ftpc->ufs) { - ufs_set_acee(ftpc->ufs, ftpc->acee); /* clear ACEE for anonymous access */ - ufs_chgdir(ftpc->ufs, "/"); /* CD to root "/" */ - } - else { - strcpy(ftpc->cwd, "SYS2"); /* Any HLQ will do */ - ftpc->flags |= FTPC_FLAG_CWDDS; /* dataset level */ - } - goto quit; - } - ftpcmsg(ftpc, "501 Syntax error in parameters"); - goto quit; - } - - memcpy(ftpc->cwd, p, len); - ftpc->cwd[len] = 0; - for(p=ftpc->cwd; *p; p++) { - *p = toupper(*p); - } - ftpc->flags = FTPC_FLAG_CWDDS; - ftpc->state = FTPSTATE_LOGIN; - - ftpcmsg(ftpc, "331 User name okay, need password"); - -quit: - return 0; -} - diff --git a/src/ftpfopen.c b/src/ftpfopen.c deleted file mode 100644 index e0f9241..0000000 --- a/src/ftpfopen.c +++ /dev/null @@ -1,173 +0,0 @@ -/* FTPDSTOR.C */ -#include "httpd.h" - -static int ftp_mvs_open(FTPC *ftpc, const char *fn, const char *fm, void **ret); -static int ftp_ufs_open(FTPC *ftpc, const char *fn, const char *fm, void **ret); - -__asm__("\n&FUNC SETC 'ftpfopen'"); -void * -ftpfopen(FTPC *ftpc, const char *fn, const char *fm, int fqnrc) -{ - int rc = 0; - void *fp = NULL; - unsigned *psa = (unsigned *)0; - unsigned *ascb = (unsigned *)psa[0x224/4]; /* A(ASCB) */ - unsigned *asxb = (unsigned *)ascb[0x6C/4]; /* A(ASXB) */ - ACEE *oldacee; - int lockrc; - - /* lock the ASXB (ENQ) address */ - lockrc = lock(asxb,0); - - oldacee = racf_get_acee() ; - - if (fqnrc == FTPFQN_RC_PATH) { - rc = try(ftp_ufs_open, ftpc, fn, fm, &fp); - } - else { - rc = try(ftp_mvs_open, ftpc, fn, fm, &fp); - } - -quit: - if (rc) { - /* restore security environment */ - racf_set_acee(oldacee); - } - - /* unlock the asxb */ - if (lockrc==0) unlock(asxb,0); - - return fp; -} - -__asm__("\n&FUNC SETC 'ftp_ufs_open'"); -static int -ftp_ufs_open(FTPC *ftpc, const char *fn, const char *fm, void **ret) -{ - UFSFILE *fp = NULL; - - /* open requested path */ - fp = ufs_fopen(ftpc->ufs, fn, fm); - if (fp) { - ftpc->fflags = FTPC_FFLAG_UFS; /* fp is a UFS file */ - } - else { - wtof("ftpfopen: ufs_fopen(\"%s\",\"%s\") failed rc=%d", - fn, fm, ufs_last_rc(ftpc->ufs)); - } - -quit: - *ret = fp; - return 0; -} - -static int -ftp_mvs_open(FTPC *ftpc, const char *fn, const char *fm, void **ret) -{ - FILE *fp = NULL; - ACEE *oldacee; - - /* set the security environment */ - oldacee = racf_set_acee(ftpc->acee); - - /* open requested dataset */ - fp = fopen(fn, fm); - if (fp) { - ftpc->fflags = FTPC_FFLAG_MVS; /* fp is a MVS dataset */ - } - else { - wtof("ftpfopen: fopen(\"%s\",\"%s\") failed", fn, fm); - } - - /* restore security environment */ - racf_set_acee(oldacee); - -quit: - *ret = fp; - return 0; -} - -#if 0 -/* old code */ -__asm__("\n&FUNC SETC 'ftp_mvs_open'"); -static int -ftp_mvs_open(FTPC *ftpc, const char *fn, const char *fm, void **ret) -{ - void *fp = NULL; - unsigned *psa = (unsigned *)0; - unsigned *ascb = (unsigned *)psa[0x224/4]; /* A(ASCB) */ - unsigned *asxb = (unsigned *)ascb[0x6C/4]; /* A(ASXB) */ - ACEE *oldacee; - int i; - int len; - char *p; - char dataset[sizeof(ftpc->cwd)+12]; -#if 0 - wtof("ftpfopen: ftp_mvs_open(\"%s\",\"%s\")", fn, fm); - wtof("ftpfopen: ftpc->cwd=\"%s\"", ftpc->cwd); -#endif - if (ftpc->flags & FTPC_FLAG_CWDDS) { - /* The current working directory is not a single dataset name */ - /* Make sure the fn looks like a dataset or dataset(member) */ - if (fn[0] == '\'') goto doit; /* looks like 'dataset' or 'dataset(member)' */ - - if ((strchr(fn,'(')) && (strchr(fn,')'))) { /* looks like dataset(member) */ - strcpy(dataset, ftpc->cwd); /* put the cwd as the dataset name */ - len = strlen(dataset); /* get the length of the dataset name */ - dataset[len++] = '.'; /* append a '.' to the dataset name */ - strcpy(&dataset[len], fn); /* copy the fn(member) to the dataset name */ - fn = dataset; /* use the cwd.dataset(member) as the fn */ - goto doit; - } - - if (strchr(fn,'.')) goto doit; /* looks like some.dataset */ - - /* otherwise we need to fail the request right now */ - wtof("ftpfopen: Current working directory is not a PDS dataset"); - goto quit; - } - - if (ftpc->flags & FTPC_FLAG_CWDPDS) { - /* The current working directory is a PDS name. */ - /* Make sure the requested file name isn't a dataset name. */ - if ((!strchr(fn, '\'')) && (!strchr(fn, '('))) { - /* we're going to assume the requested file name is a member name */ - strcpy(dataset, ftpc->cwd); /* put the cwd as the dataset name */ - len = strlen(dataset); /* get the length of the dataset name */ - dataset[len++] = '('; /* append a '(' for the member name */ - for(i=0; i < 8; i++) { - if (!fn[i]) break; /* break if end of string */ - if (fn[i]=='.') break; /* break if file extension */ - dataset[len+i] = fn[i]; /* copy to member name */ - } - len+=i; - dataset[len++] = ')'; /* append a ')' for the member name */ - dataset[len] = 0; /* terminate dataset name with 0 byte */ - fn = dataset; /* use the dataset(member) as the fn */ - } - } - -doit: - /* set the security environment */ - oldacee = racf_set_acee(ftpc->acee); - - /* open requested dataset */ -#if 0 - wtof("ftpfopen: fopen(\"%s\",\"%s\")", fn, fm); -#endif - fp = fopen(fn, fm); - if (fp) { - ftpc->fflags = FTPC_FFLAG_MVS; /* fp is a MVS dataset */ - } - else { - wtof("ftpfopen: fopen(\"%s\",\"%s\") failed", fn, fm); - } - - /* restore security environment */ - racf_set_acee(oldacee); - -quit: - *ret = fp; - return 0; -} -#endif /* old code */ diff --git a/src/ftpfqn.c b/src/ftpfqn.c deleted file mode 100644 index 8de98f5..0000000 --- a/src/ftpfqn.c +++ /dev/null @@ -1,382 +0,0 @@ -#include "httpd.h" - -static int isdataset(const char *name); -static int ismember(const char *name); -static int ispattern(const char *name, const char *pattern); -static char *resolve_path(char *path); -static char *strupper(char *buf); - -/* uses ftpc and in parameters to construct a fully qualified name in out */ -int -ftpfqn(FTPC *ftpc, const char *in, char *out) -{ - int rc = FTPFQN_RC_PARMS; - int dataset = 0; - int member = 0; - int path = 0; - int i; - char buf[256]= ""; - - if (!ftpc) goto quit; - if (!in) goto quit; - if (!out) goto quit; - - // wtof("%s: in=\"%s\"", __func__, in); - - strncpy(buf, in, sizeof(buf)); - buf[sizeof(buf)-1] = 0; - - if (buf[0] == '\'') { - /* in is a dataset name */ - char *e = strrchr(&buf[1], '\''); - - if (e) *e = 0; /* strip trailing single quote */ - - strcpy(buf, &buf[1]); - strupper(buf); - - dataset = isdataset(buf); - if (dataset) { - if (ismember(buf)) { - /* name is a single level high level qualifier */ - rc = FTPFQN_RC_HLQ; - } - else if (ispattern(buf, "*.*(*)")) { - /* name looks like a datset with member */ - rc = FTPFQN_RC_DSNMEM; - } - else { - /* name is a dataset */ - rc = FTPFQN_RC_DSN; - } - strcpy(out, buf); - goto quit; - } - - rc = FTPFQN_RC_ERROR; - goto quit; - } - - if (buf[0] == '/') { - /* in is a path name */ - strcpy(out, buf); - resolve_path(out); - rc = FTPFQN_RC_PATH; - goto quit; - } - - if (strcmp(in, "..")==0) { - /* resove cwd to higher level */ - if ((ftpc->flags & FTPC_FLAG_CWDDS) || (ftpc->flags & FTPC_FLAG_CWDPDS)) { - char *dot; - - strcpy(out, ftpc->cwd); - dot = strrchr(out, '.'); - if (dot) *dot = 0; - - if (strchr(out, '.')) { - rc = FTPFQN_RC_DSN; - } - else { - rc = FTPFQN_RC_HLQ; - } - goto quit; - } - - if (ftpc->ufs && ftpc->ufs->cwd.path[0]) { - char *dir; - - strcpy(out, ftpc->ufs->cwd.path); - dir = strrchr(out+1, '/'); - if (dir) { - /* truncate path by one level */ - *dir = 0; - } - else { - /* truncate at root name "/" */ - out[1] = 0; - } - rc = FTPFQN_RC_PATH; - goto quit; - } - } - - if (ftpc->flags & FTPC_FLAG_CWDDS) { - /* The cwd is a dataset list prefix */ - if (in[0]=='(') { - /* the input name looks like a "(member)" */ - sprintf(buf, "%s%s", ftpc->cwd, in); - } - else { - /* The input name *should* be "names" or "name(member)"*/ - sprintf(buf, "%s.%s", ftpc->cwd, in); - } - } - - if (ftpc->flags & FTPC_FLAG_CWDPDS) { - /* The cwd is the PDS name */ - if (in[0]=='(') { - /* the input name looks like a "(member)" */ - sprintf(buf, "%s%s", ftpc->cwd, in); - } - else { - /* The input name *should* be "member" */ - sprintf(buf, "%s(%s)", ftpc->cwd, in); - } - } - - if ((ftpc->flags & FTPC_FLAG_CWDDS) || (ftpc->flags & FTPC_FLAG_CWDPDS)) { - strupper(buf); - dataset = isdataset(buf); - if (dataset) { - if (ispattern(buf, "*(*)")) { - /* name looks like a datset with member */ - rc = FTPFQN_RC_DSNMEM; - } - else { - /* name is a dataset */ - rc = FTPFQN_RC_DSN; - } - strcpy(out, buf); - goto quit; - } - - rc = FTPFQN_RC_ERROR; - goto quit; - } - - if (ftpc->ufs) { - if (ftpc->ufs->cwd.path[0]) { - sprintf(out, "%s/%s", ftpc->ufs->cwd.path, buf); - } - else { - sprintf(out, "%s/%s", ftpc->cwd, buf); - } - resolve_path(out); - - rc = FTPFQN_RC_PATH; - goto quit; - } - - rc = FTPFQN_RC_ERROR; - -quit: -#if 0 - wtof("%s: out=\"%s\" rc=%d %s", __func__, out, rc, - rc==FTPFQN_RC_PARMS ? "PARMS" : - rc==FTPFQN_RC_ERROR ? "ERROR" : - rc==FTPFQN_RC_PATH ? "PATH" : - rc==FTPFQN_RC_HLQ ? "HLQ" : - rc==FTPFQN_RC_DSN ? "DSN" : - rc==FTPFQN_RC_DSNMEM? "DSNMEM": "???"); -#endif - return rc; -} - -static char * -resolve_path(char *path) -{ - char *p; - int len; - - if (!path) goto quit; - - // wtof(" %s: in path=\"%s\"", __func__, path); - - if (*path != '/') goto quit; - - /* transform "//" to "/" */ - while(p=strstr(path, "//")) { - strcpy(p, p+1); - } - - /* transform "/some/name/../bob" to "/some/bob" */ - /* transform "/some/.." to "/" */ - while(p=strstr(path, "/..")) { - char *slash; - - if (strcmp(path, "/..") == 0) { - strcpy(path, "/"); - continue; - } -#if 1 - /* did we find "/.." at the start of the path name? */ - if (p==path) { - /* Yes, do we have anything following the "/.." ? */ - // wtof(" %s: p==path: path+1=\"%s\" p+3=\"%s\"", __func__, path+1, p+3); - if (*(p+3)=='/') { - /* Yes, copy it to the start of the path */ - strcpy(path, p+3); - } - else { - /* No, copy it after the "/" */ - strcpy(path+1, p+3); - } - continue; - } -#endif - - *p = 0; - slash = strrchr(path, '/'); - if (slash) { - // wtof(" %s: slash: slash=\"%s\" p+3=\"%s\"", __func__, slash, p+3); - if (*(p+3)=='/') { - strcpy(slash, p+3); - } - else { - strcpy(slash+1, p+3); - } - continue; - } - break; - } - - /* transform "/some/name/./blivit" to "/some/name/blivit" */ - while(p=strstr(path, "/.")) { - if (p[2]=='/') { - strcpy(p, p+2); - } - else { - strcpy(p+1, p+2); - } - } - - /* remove any trailing '/' from path name */ - for(len = strlen(path); len > 1; len--) { - p = &path[len-1]; - if (*p!='/') break; - *p = 0; - } - -quit: - // wtof(" %s: out path=\"%s\"", __func__, path); - return path; -} - -static int -isdataset(const char *name) -{ - int dataset = 0; - int levels = 0; - int member = 0; - int len; - char buf[256]; - char *p; - - strcpy(buf, name); - - if (ismember(buf)) { - /* looks like a single high level qualifier */ - if (!isdigit(buf[0])) { - dataset = 1; - goto quit; - } - } - - if (strstr(buf, "..")) goto quit; /* can't have and empty dataset level name */ - - for(p = strtok(buf, "."); p; p = strtok(NULL, ".")) { - char *lparen = strchr(p, '('); - char *rparen = strrchr(p, ')'); - - // wtof(" %s: p=\"%s\"", __func__, p ? p : "(null)"); - if (lparen && rparen) { - if (member) goto quit; /* we've already seen a member so die */ - member++; - *lparen = 0; - *rparen = 0; - } - - levels++; - len = strlen(p); - - if (len < 1) goto quit; /* dataset level name too short */ - if (len > 8) goto quit; /* dataset level name too long */ - if (isdigit(p[0])) goto quit; /* dataset level name can not start with a number */ - if (!ismember(p)) goto quit; /* bad character in name */ - - if (lparen && rparen) { - if (strlen(lparen+1) > 8) goto quit; /* dataset level name too long */ - if (!ismember(lparen+1)) goto quit; /* bad character in name */ - - *lparen = '('; - *rparen = ')'; - } - - } - - /* name could be a dataset */ - if (levels <= 22) { - int maxlen = 44; - - if (member > 1) goto quit; /* only 1 member allowed */ - - if (member) { - maxlen += 10; /* maxlen += strlen("(12345678)") */ - } - - if (strlen(name) <= maxlen) { - dataset = 1; - } - } - -quit: - // wtof(" %s(\"%s\") %s", __func__, name, dataset ? "SUCCESS" : "FAILED"); - return dataset; -} - -static int -ismember(const char *name) -{ - int member = 0; - int len = strlen(name); - int i; - - if (len < 1) goto quit; /* invalid member name */ - - if (len <= 8) { - member = 1; /* assume the name is a valid member name */ - for(i=0; name[i]; i++) { - if (name[i]=='@') continue; - if (name[i]=='#') continue; - if (name[i]=='$') continue; - if (isalnum(name[i])) continue; - - /* not a valid character for a member name */ - member = 0; - break; - } - } - -quit: - // wtof(" %s(\"%s\") %s", __func__, name, member ? "SUCCESS" : "FAILED"); - return member; -} - -static char * -strupper(char *buf) -{ - int i; - - if (!buf) goto quit; - - for(i=0; buf[i]; i++) { - if (islower(buf[i])) { - buf[i] = (char) toupper(buf[i]); - } - } - -quit: - return buf; -} - -static int -ispattern(const char *name, const char *pattern) -{ - int rc = __patmat(name, pattern); - - // wtof(" %s(\"%s\",\"%s\") %s", __func__, name, pattern, rc ? "MATCHED" : "NOMATCH"); - - return rc; -} - diff --git a/src/ftpslist.c b/src/ftpslist.c deleted file mode 100644 index 01d0ebf..0000000 --- a/src/ftpslist.c +++ /dev/null @@ -1,168 +0,0 @@ -/* FTPSLIST.C */ -#include "httpd.h" -#include "cliblist.h" -#include "clibary.h" - -int -ftpslist(FTPC *ftpc, int brief) -{ - PDSLIST **pdslist = 0; - LOADSTAT *loadstat = 0; - ISPFSTAT *ispfstat = 0; - DSLIST **dslist = 0; - DSLIST *d = 0; - int rc = 0; - char *p = 0; - unsigned count = 0; - unsigned n = 0; - char buf[256]; - const char *cwd = ftpc->cwd; - - if (!ftpc->ufs) goto do_open; - if (ftpc->flags & FTPC_FLAG_CWDDS) goto do_open; - if (ftpc->flags & FTPC_FLAG_CWDPDS) goto do_open; - - cwd = ftpc->ufs->cwd.path; - -do_open: - /* lets first try to open the data connection */ - rc = ftpcopen(ftpc); - if (rc < 0) { - ftpcmsg(ftpc, "425 Can't open data connection"); - goto quit; - } - /* wtof("%s cwd=\"%s\", data socket=%d", __func__, cwd, rc); */ - ftpc->data_socket = rc; /* data connection socket */ - - /* data connection is opened--list directory information */ - p = strtok(ftpc->cmd, " "); - if (p) p = strtok(NULL, " "); - if (p) { - if (strcmp(p, "*.*")==0) { - p = 0; - } - } - - /* is the CWD a PDS? */ - if (ftpc->flags & FTPC_FLAG_CWDPDS) { - /* create directory list for PDS */ - /* wtof("%s create PDS member list for cwd=\"%s\"", __func__, cwd); */ - pdslist = __listpd(cwd, p); - if (pdslist) { - loadstat = (LOADSTAT *)buf; - ispfstat = (ISPFSTAT *)buf; - count = __arcou(&pdslist); - for(n=0; n < count; n++) { - PDSLIST *a = pdslist[n]; - if (!a) continue; - if (brief) { - /* name list only, so no need to format the udata */ - ftpcprtf(ftpc, "%s\r\n", a->name); - continue; - } - if (a->idc & PDSLIST_IDC_TTRS) { - /* most likely a load member */ - __fmtloa(a, loadstat); - ftpcprtf(ftpc, "%-8.8s %s %s %-8.8s %s %s %s\r\n", - loadstat->name, loadstat->ttr, loadstat->size, - loadstat->aliasof, loadstat->ac, loadstat->ep, - loadstat->attr); - } - else { - /* most likely a non-load member */ - __fmtisp(a, ispfstat); - ftpcprtf(ftpc, "%-8.8s %s %s %s %s %s %s %s %s\r\n", - ispfstat->name, ispfstat->ttr, ispfstat->ver, - ispfstat->created, ispfstat->changed, ispfstat->init, - ispfstat->size, ispfstat->mod, ispfstat->userid); - } - } - } - goto done; - } - - /* is the CWD a DATASET level? */ - if (ftpc->flags & FTPC_FLAG_CWDDS) { - /* create list of datasets */ - /* wtof("%s create list of datasets cwd=\"%s\"", __func__, cwd); */ - dslist = __listds(cwd, "NONVSAM VOLUME", NULL); - count = __arcou(&dslist); - for(n=0; n < count; n++) { - d = dslist[n]; - if (!d) continue; - ftpcprtf(ftpc, - "%-44.44s " /* dsn */ - "%-6.6s " /* volser */ - "%5u " /* lrecl */ - "%5u " /* blksize */ - "%s " /* dsorg */ - "%-3s " /* recfm */ - "%u/%02u/%02u " /* create date */ - "%u/%02u/%02u\r\n", /* reference date */ - d->dsn, - d->volser, - d->lrecl, - d->blksize, - d->dsorg, - d->recfm, - d->cryear, d->crmon, d->crday, - d->rfyear, d->rfmon, d->rfday); - } - goto done; - } - - if (ftpc->ufs) { - UFSDDESC *desc = ufs_diropen(ftpc->ufs, cwd, NULL); - UFSDLIST *list; - struct tm *tm; - char fmtdate[26]; - - if (desc) { - for(list=ufs_dirread(desc); list; list=ufs_dirread(desc)) { - count++; - if (brief) { - ftpcprtf(ftpc, "%s%s\r\n", list->name, list->attr[0]=='d' ? "/" : ""); - } - else { - tm = mlocaltime64(&list->mtime); - if (tm) { - strftime(fmtdate, sizeof(fmtdate), "%Y %b %d %H:%M", tm); - } - else { - strcpy(fmtdate, "1970 Jan 01 00:00"); - } - ftpcprtf(ftpc, "%s %3u %-8.8s %-8.8s %6u %s %s\r\n", - list->attr, list->nlink, list->owner, list->group, - list->filesize, fmtdate, list->name); - } - } - ufs_dirclose(&desc); - } - - if (!count) { - /* no directory list was returned, gripe using errno */ - ftpcmsg(ftpc, "226-%s", strerror(errno)); - } - goto done; - } - - /* otherwise, the contents of ftpc->cwd *should* replesent a unix like file system path */ - /* wtof("%s create directory list for cwd=\"%s\"", __func__, cwd); */ - -done: - if (count) { - ftpcmsg(ftpc, "250 Requested file action okay, completed"); - } - else { - ftpcmsg(ftpc, "226 Closing data connection"); - } - - closesocket(ftpc->data_socket); - ftpc->data_socket = -1; - -quit: - if (pdslist) __freepd(&pdslist); - if (dslist) __freeds(&dslist); - - return 0; -} diff --git a/src/httpcons.c b/src/httpcons.c index d5642e4..80e2d4c 100644 --- a/src/httpcons.c +++ b/src/httpcons.c @@ -286,12 +286,6 @@ d_port(char *buf) int rc = 0; wtof("HTTPD102I HTTPD server listening on port %d", httpd->port); - if (httpd->ftpd) { - FTPD *ftpd = httpd->ftpd; - if (ftpd->port) { - wtof("HTTPD102I FTPD server listening on port %d", ftpd->port); - } - } quit: return rc; @@ -564,7 +558,6 @@ d_queue(CTHDWORK *work) CTHDQUE *q = work->queue; if (q->data) { HTTPC *httpc = q->data; - FTPC *ftpc = q->data; struct sockaddr addr; struct sockaddr_in *in = (struct sockaddr_in*)&addr; int addrlen; @@ -594,23 +587,6 @@ d_queue(CTHDWORK *work) wtof("HTTPD120I ..SOCKET %8d ....PORT %8d ......IP %s", httpc->socket, in->sin_port, ip); } - else if (strcmp(ftpc->eye, FTPC_EYE)==0) { - ACEE *acee = ftpc->acee; - - if (acee) { - memcpyp(user, sizeof(user), &acee->aceeuser[1], acee->aceeuser[0], 0); - memcpyp(group, sizeof(group), &acee->aceegrp[1], acee->aceegrp[0], 0); - } - ntoa(ftpc->client_addr, ip); - wtof("HTTPD118I PROTOCOL FTP ....USER %-9.9s ...GROUP %s", user, group); - wtof("HTTPD119I ..REMOTE CLIENT ....PORT %8d ......IP %s", - ftpc->client_port, ip); - addrlen = sizeof(addr); - getpeername(ftpc->client_socket, &addr, &addrlen); - ntoa(in->sin_addr.s_addr, ip); - wtof("HTTPD120I ..SOCKET %8d ....PORT %8d ......IP %s", - ftpc->client_socket, in->sin_port, ip); - } } return 0; } @@ -683,10 +659,6 @@ d_thread(char *buf) d_cthdtask(httpd->socket_thread); wtof("HTTPD119I ..SOCKET %8d ....PORT %8d (HTTP Protocol)", httpd->listen, httpd->port); - if (httpd->ftpd) { - wtof("HTTPD119I ..SOCKET %8d ....PORT %8d (FTP Protocol)", - httpd->ftpd->listen, httpd->ftpd->port); - } wtof(HTTPD199I); } diff --git a/src/httpd.c b/src/httpd.c index 6f3e48b..31098a9 100644 --- a/src/httpd.c +++ b/src/httpd.c @@ -248,7 +248,6 @@ terminate(void) { CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; - FTPD *ftpd = httpd->ftpd; HTTPC *httpc; int i; unsigned count; @@ -256,12 +255,6 @@ terminate(void) http_enter("terminate()\n"); - if (ftpd) { - ftpdterm(&ftpd); - httpd->ftpd = 0; - http_pubf(httpd, "thread/listener/ftp", ""); - } - httpd->flag |= HTTPD_FLAG_QUIESCE; httpd->flag |= HTTPD_FLAG_SHUTDOWN; @@ -409,12 +402,10 @@ build_fd_set(fd_set *read, fd_set *write, fd_set *excp) { CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; - FTPD *ftpd = httpd->ftpd; int maxsock = 0; unsigned count = array_count(&httpd->httpc); unsigned n; HTTPC *httpc; - FTPC *ftpc; #if 0 http_enter("build_fd_set()\n"); #endif @@ -442,37 +433,6 @@ build_fd_set(fd_set *read, fd_set *write, fd_set *excp) if (excp) FD_SET(httpc->socket, excp); } - if (ftpd && ftpd->listen >= 0) { - /* include the FTPD listener socket */ - if (read && ftpd->listen) { - FD_SET(ftpd->listen, read); - if (ftpd->listen > maxsock) maxsock = ftpd->listen; - } -#if 0 /* clients are processed only in the worker threads */ - /* include any FTPD client sockets */ - count = array_count(&ftpd->ftpc); - for(n=0; n < count; n++) { - ftpc = ftpd->ftpc[n]; - if (!ftpc) continue; /* no client handle? */ - - if (ftpc->client_socket >= 0) { - /* the clients control channel socket */ - if (ftpc->client_socket > maxsock) maxsock = ftpc->client_socket; - if (read) FD_SET(ftpc->client_socket, read); - if (write) FD_SET(ftpc->client_socket, write); - if (excp) FD_SET(ftpc->client_socket, excp); - } - if (ftpc->data_socket >= 0) { - /* the clients data channel socket */ - if (ftpc->data_socket > maxsock) maxsock = ftpc->data_socket; - if (read) FD_SET(ftpc->data_socket, read); - if (write) FD_SET(ftpc->data_socket, write); - if (excp) FD_SET(ftpc->data_socket, excp); - } - } -#endif - } - quit: if (maxsock) maxsock++; #if 0 @@ -486,9 +446,6 @@ process_clients(fd_set *read, fd_set *write, fd_set *excp) { CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; -#if 0 - FTPD *ftpd = httpd->ftpd; -#endif int rc = http_process_clients(); int lockrc; unsigned count; @@ -524,13 +481,6 @@ process_clients(fd_set *read, fd_set *write, fd_set *excp) } if (lockrc==0) unlock(httpd, 0); -#if 0 /* clients are processed only in the worker threads */ - if (!ftpd) goto quit; - - /* process ftp clients (does its own locking */ - rc = ftpd_process_clients(); -#endif - quit: return 0; } @@ -541,7 +491,6 @@ socket_thread(void *arg1, void *arg2) CLIBCRT *crt = __crtget(); CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; - FTPD *ftpd = httpd->ftpd; unsigned *psa = (unsigned *)0; unsigned *tcb = (unsigned *)psa[0x21C/4]; /* A(TCB) from PSATOLD */ unsigned *ascb = (unsigned *)psa[0x224/4]; /* A(ASCB) from PSAAOLD */ @@ -551,7 +500,6 @@ socket_thread(void *arg1, void *arg2) int sock; int len; HTTPC *httpc; - FTPC *ftpc; timeval wait; int maxsock; unsigned count; @@ -689,65 +637,6 @@ socket_thread(void *arg1, void *arg2) } } /* if (FD_ISSET(httpd->listen, &read)) */ - if (ftpd) { - /* check for new connections */ - if (FD_ISSET(ftpd->listen, &read)) { - /* new client wants to connect */ - len = sizeof(addr); - sock = accept(ftpd->listen, &addr, &len); - if (sock<0) { - wtof("FTPD0052E accept() failed, rc=%d, error=%d\n", - sock, errno); - http_dbgf("accept() failed, rc=%d, error=%d\n", sock, errno); - goto quit; - } - - http_dbgf("new connection on socket=%d\n", sock); - /* wtof("%s new connection on socket=%d", __func__, sock); */ - -#if 0 /* we want the FTP control socket to block */ - len = 1; /* set non-blocking I/O */ - if (ioctlsocket(sock, FIONBIO, &len)) { - wtof("FTPD0053E Unable to set non-blocking I/O for socket %d\n", - sock); - http_dbgf("Unable to set non-blocking I/O for socket %d\n", - sock); - } -#endif - /* we've accepted a connection */ - ftpc = calloc(1, sizeof(FTPC)); - if (!ftpc) { - wtof("FTPD0999E Out of memory!"); - goto quit; - } - strcpy(ftpc->eye, FTPC_EYE); - ftpc->ftpd = ftpd; - ftpc->client_socket = sock; - ftpc->client_addr = a->sin_addr.s_addr; - ftpc->client_port = a->sin_port; - ftpc->data_socket = -1; - ftpc->state = FTPSTATE_INITIAL; - ftpdsecs(&ftpc->start); - - mgr = httpd->mgr; - if (mgr) { - /* we have a thread manager */ - if (mgr->state == CTHDMGR_STATE_QUIESCE || - mgr->state == CTHDMGR_STATE_STOPPED) { - /* manager is not available */ - ftpcterm(&ftpc); - } - else { - /* queue client to thread manager work queue */ - cthread_queue_add(mgr, ftpc); - } - } - else { - /* add new client to array of clients */ - array_add(&ftpd->ftpc, ftpc); - } - } /* if (FD_ISSET(ftpd->listen, &read)) */ - } /* if (ftpd) */ } /* while(task) */ quit: @@ -1111,7 +1000,6 @@ worker_thread(void *udata, CTHDWORK *work) CLIBCRT *crt = __crtget(); /* A(CLIBCRT) from TCBUSER */ CLIBGRT *grt = __grtget(); HTTPD *httpd = grt->grtapp1; - FTPD *ftpd = httpd->ftpd; HTTPT *httpt = httpd->httpt; /* Telemtry handle */ unsigned *psa = (unsigned *)0; unsigned *tcb = (unsigned *)psa[0x21C/4]; /* A(TCB) from PSATOLD */ @@ -1121,7 +1009,6 @@ worker_thread(void *udata, CTHDWORK *work) int rc = 0; char *data = NULL; HTTPC *httpc = NULL; - FTPC *ftpc = NULL; char *timebuf; char topic[40]; unsigned n, count; @@ -1166,7 +1053,6 @@ worker_thread(void *udata, CTHDWORK *work) if (rc == CTHDWORK_POST_REQUEST) { /* process request */ httpc = (HTTPC*)data; - ftpc = (FTPC*)data; if (httpc && strcmp(httpc->eye, HTTPC_EYE)==0) { while(httpc->state != CSTATE_CLOSE) { http_process_client(httpc); @@ -1176,13 +1062,6 @@ worker_thread(void *udata, CTHDWORK *work) httpc, httpc->socket); http_close(httpc); } - else if (ftpc && strcmp(ftpc->eye, FTPC_EYE)==0) { - while(ftpc->state != FTPSTATE_TERMINATE) { - ftpd_process_client(ftpc); - if (work->state == CTHDWORK_STATE_SHUTDOWN) break; - } - ftpcterm(&ftpc); - } else { wtodumpf(data, 16, "%s unknown request", __func__); } diff --git a/src/httpdsrv.c b/src/httpdsrv.c index e094920..e1fe619 100644 --- a/src/httpdsrv.c +++ b/src/httpdsrv.c @@ -12,7 +12,6 @@ static int display_httpd(HTTPD *httpd, HTTPC *httpc); static int display_cgi(HTTPD *httpd, HTTPC *httpc); static int display_file(HTTPD *httpd, HTTPC *httpc); static int display_fs(HTTPD *httpd, HTTPC *httpc); -static int display_ftpd(HTTPD *httpd, HTTPC *httpc); static int display_mgr(HTTPD *httpd, HTTPC *httpc); static int display_task(HTTPD *httpd, HTTPC *httpc); static int display_ufsdisks(HTTPD *httpd, HTTPC *httpc); @@ -81,11 +80,6 @@ int main(int argc, char **argv) goto quit; } - if (http_cmpn(target, "FTPD", len)==0) { - display_ftpd(httpd, httpc); - goto quit; - } - if (http_cmpn(target, "MGR", len)==0) { display_mgr(httpd, httpc); goto quit; @@ -384,14 +378,7 @@ display_httpd(HTTPD *httpd, HTTPC *httpc) "%-24.24s\n", O(uptime), ctime64(&httpd->uptime)); - http_printf(httpc, - "+%04X" - "httpd->ftpd" - "Embedded FTP Server Handle" - "%p\n", - O(ftpd), httpd->ftpd); - - http_printf(httpc, + http_printf(httpc, "+%04X" "httpd->ufssys" "UFS System Handle" @@ -1471,165 +1458,6 @@ struct ufs { }; /* 20 (32 bytes) */ #endif -#ifdef O -#undef O -#endif -#define O(a) ((unsigned)&(ftpd->a) - (unsigned)ftpd) - -static int -display_ftpd(HTTPD *httpd, HTTPC *httpc) -{ - int rc = 0; - FTPD *ftpd = httpd->ftpd; - unsigned n, count; - UCHAR *u; - - if (rc = send_resp(httpd, httpc, 200) < 0) goto quit; - - http_printf(httpc, "

FTPD Handle %p

\n", ftpd); - -#if 0 - http_printf(httpc, - "\n", - ftpd, sizeof(FTPD)); -#endif - display_memory(httpd, httpc, "FTPD", ftpd, sizeof(FTPD), 16); - - http_printf(httpc, "\n"); - - http_printf(httpc, - "" - "" - "" - "\n"); - - http_printf(httpc, - "" - "" - "" - "\n", - O(eye), ftpd->eye); - - if (ftpd->ftpd_thread) { - http_printf(httpc, - "" - "" - "" - "\n", - O(ftpd_thread), ftpd->ftpd_thread, ftpd->ftpd_thread); - } - else { - http_printf(httpc, - "" - "" - "" - "\n", - O(ftpd_thread), ftpd->ftpd_thread); - } - - count = array_count(&ftpd->ftpc); - if (count) { - http_printf(httpc, - "" - "" - "" - "\n", - O(ftpc), ftpd->ftpc, ftpd->ftpc); - } - else { - http_printf(httpc, - "" - "" - "" - "\n", - O(ftpc), ftpd->ftpc); - } - - u = (unsigned char*)&ftpd->addr; - http_printf(httpc, - "" - "" - "" - "\n", - O(addr), u[0], u[1], u[2], u[3]); - - http_printf(httpc, - "" - "" - "" - "\n", - O(port), ftpd->port); - - http_printf(httpc, - "" - "" - "" - "\n", - O(listen), ftpd->listen); - - if (ftpd->stats) { - http_printf(httpc, - "" - "" - "" - "\n", - O(stats), ftpd->stats, ftpd->stats); - } - else { - http_printf(httpc, - "" - "" - "" - "\n", - O(stats), ftpd->stats); - } - - if (ftpd->dbg) { - http_printf(httpc, - "" - "" - "" - "\n", - O(dbg), ftpd->dbg, ftpd->dbg); - } - else { - http_printf(httpc, - "" - "" - "" - "\n", - O(dbg), ftpd->dbg); - } - - http_printf(httpc, - "" - "" - "" - "\n"); - - http_printf(httpc, - "" - "" - "" - "\n", - O(sys), ftpd->sys, ftpd->sys); - -done: - http_printf(httpc, "
OffsetData NameDescriptionContents
+%04Xftpd->eyeEye Catcher\"%s\"
+%04Xftpd->ftpd_threadSubtask Thread Handle%p
+%04Xftpd->ftpd_threadSubtask Thread Handle%p
+%04Xftpd->ftpcFTP Clients Array%p
+%04Xftpd->ftpcFTP Clients Array%p
+%04Xftpd->addrFTPD Listen Address%u.%u.%u.%u
+%04Xftpd->portFTPD Listen Port%d
+%04Xftpd->listenFTPD Listen Socket%d
+%04Xftpd->statsFTP Statistics File%p
+%04Xftpd->statsFTPD Statistics File%p
+%04Xftpd->dbgFTP Debug File%p
+%04Xftpd->dbgFTPD Debug File%p
+%04Xftpd->flagsFTPD Processing Flags%02X", - O(flags), ftpd->flags); - if (ftpd->flags & FTPD_FLAG_INIT) http_printf(httpc, " INIT"); - if (ftpd->flags & FTPD_FLAG_LISTENER) http_printf(httpc, " LISTENER"); - if (ftpd->flags & FTPD_FLAG_READY) http_printf(httpc, " READY"); - if (ftpd->flags & FTPD_FLAG_QUIESCE) http_printf(httpc, " QUIESCE"); - if (ftpd->flags & FTPD_FLAG_SHUTDOWN) http_printf(httpc, " SHUTDOWN"); - http_printf(httpc, "
+%04Xftpd->sysUnix \"like\" File System Handle%p
\n"); - send_last(httpd, httpc); - -quit: - return 0; -} - - #ifdef O #undef O #endif @@ -2353,7 +2181,6 @@ static int display_queue_data(HTTPD *httpd, HTTPC *httpc, CTHDQUE *q) { HTTPC *h = q->data; - FTPC *ftpc = q->data; struct sockaddr addr; struct sockaddr_in *in = (struct sockaddr_in*)&addr; int addrlen; @@ -2432,34 +2259,6 @@ display_queue_data(HTTPD *httpd, HTTPC *httpc, CTHDQUE *q) goto quit; } - if (strcmp(ftpc->eye, FTPC_EYE)==0) { - ACEE *acee = ftpc->acee; - - if (acee) { - memcpyp(user, sizeof(user), &acee->aceeuser[1], acee->aceeuser[0], 0); - memcpyp(group, sizeof(group), &acee->aceegrp[1], acee->aceegrp[0], 0); - } - - addrlen = sizeof(addr); - getsockname(ftpc->client_socket, &addr, &addrlen); - ntoa(in->sin_addr.s_addr, ip); - - http_printf(httpc, "
\n");
-        http_printf(httpc, "PROTOCOL        FTP\n");
-        http_printf(httpc, "USER            %-9.9s\n", user);
-        http_printf(httpc, "GROUP           %s\n", group);
-        http_printf(httpc, "SOCKET          %d\n", ftpc->client_socket);
-        http_printf(httpc, "LOCAL           %s:%d\n", ip, in->sin_port);
-
-        addrlen = sizeof(addr);
-        getpeername(ftpc->client_socket, &addr, &addrlen);
-        ntoa(in->sin_addr.s_addr, ip);
-        http_printf(httpc, "REMOTE          %s:%d\n", ip, in->sin_port);
-        http_printf(httpc, "
\n"); - - goto quit; - } - quit: return 0; } @@ -2635,9 +2434,6 @@ display_help(HTTPD *httpd, HTTPC *httpc) http_printf(httpc, "
?target=FS
\n"); http_printf(httpc, "
Display the HTTPD ... Unix \"like\" File System Handle.

\n"); - http_printf(httpc, "
?target=FTPD
\n"); - http_printf(httpc, "
Display the HTTPD ... FTPD Handle.

\n"); - http_printf(httpc, "
?target=HELP
\n"); http_printf(httpc, "
Display this help text.

\n");