Posted: Mon Apr 07, 2003 6:59 am
Restored from previous forum. Originally posted by Kendrel.
i would like to code a hook dll for servu (an ftp server), but iam having (shame on me) problems to convert it. most problem for me seems to be the char array inside the structure... i dunno how to convert this in purebasic.
i will post the full source (it is not that much), and would be very glad if someone could convert it, but converting the structures would be a good start aswell... thx in advance...
here comes the header file
// WULOG.H
// =======
//
// WU_FTP logfile format DLL for use with Serv-U v2.2 and higher.
// Code can be found in WULOG.CPP.
//
#ifndef WULOGH // avoid multiple inclusion
#define WULOGH
using namespace std; // to use standard lib identifiers
// Serv-U event definitions
// a copy of the list found in the Serv-U manual
#define EVNT_None 0 // none
#define EVNT_IPName 1 // symbolic IP name available
#define EVNT_Connect 2 // connection was made
#define EVNT_Close 3 // closed connection
#define EVNT_BouncedIP 4 // bounced client because of IP address
#define EVNT_TooMany 5 // bounced user because there are too many
#define EVNT_WrongPass 6 // too many times wrong password
#define EVNT_TimeOut 7 // connection timed out
#define EVNT_Login 8 // use logged in
#define EVNT_StartUp 9 // start upload of file
#define EVNT_EndUp 10 // successfull upload of file
#define EVNT_StartDown 11 // start of download of file
#define EVNT_EndDown 12 // successfull download of file
#define EVNT_AbortUp 13 // aborted upload
#define EVNT_AbortDown 14 // aborted download
#define EVNT_Rename 15 // renamed file/dir
#define EVNT_DelFile 16 // deleted file
#define EVNT_DelDir 17 // deleted dir
#define EVNT_ChgDir 18 // changed working directory
#define EVNT_MakeDir 19 // created directory
// Serv-U event hook definitions
#define EVNT_HookDown 100 // hook for file downloads
#define EVNT_HookUp 101 // hook for file uploads
#define EVNT_HookAppend 102 // hook for append file upload
#define EVNT_HookUnique 103 // hook for unique name upload
#define EVNT_HookRename 104 // hook for rename file/dir
#define EVNT_HookDelFile 105 // hook for delete file
#define EVNT_HookDelDir 106 // hook for delete dir
#define EVNT_HookMkd 107 // hook for make directory
#define EVNT_HookRmd 108 // hook for remove directory
// Serv-U sub-event codes
#define SEVNT_None 0 // no sub-event
#define SEVNT_ErrWrite 1 // problem writing to disk
#define SEVNT_ErrRead 2 // problem reading from disk
#define SEVNT_ErrQuota 3 // insufficient disk quota
#define SEVNT_ErrTOut 4 // packet timed out
#define SEVNT_ErrAbort 5 // user aborted transfer
#define SEVNT_ErrUnknown 6 // unknown error
#define SEVNT_ErrClose 7 // data connection closed unexpectedly
// return codes for hooks
#define REVNT_None 0 // nothing
#define REVNT_Proceed 1 // let event pass
#define REVNT_Abort 2 // stop event
#define REVNT_Suspend 3 // suspend event until decision is made
// event information structure for communications with DLL's
struct RFTPEventStr {
// event info
DWORD Event; // event type
DWORD SubEvent; // sub-event type
// user info
DWORD SessionID; // unique ID of the FTP session
char User[40]; // user name
char ClientIP[16]; // IP number of client
char LocalIP[16]; // IP number the client connected to
// event attributes
DWORD Duration; // duration of events
DWORD Size; // size of object (ie. file)
// hook info
HWND hWindow; // window handle to post decision to
UINT Message; // message to post
char* pReplyText; // pointer to text to send to user
// scratch pad area
char AuxOne[512]; // auxiliary area one
char AuxTwo[512]; // auxiliary area two
};
// user info structure to keep track of sessions
struct RUserInfoStr {
DWORD SessionID; // session ID
string IPName; // IP name of user (if available)
string AnonPass; // anonymous password used to log in (for anonymous users)
};
// some definitions to make life easier
typedef RSimpleList LSTUINFO; // simple linked list of user info structures
#define EXPORT extern "C" __declspec (dllexport) // exported functions declaration header
#define MAXPATH 300 // maximum path length, used for declaring long strings
// text constants
#define INIFILE "wulog.ini" // .ini file name
#define INISECTION "LOG" // .ini file section header used
#define INILOGFILE "FileName" // .ini file logfile line
// function definitions
EXPORT WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc);
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB);
void LoadIniFile(HINSTANCE hInst); // process .ini file
void LogLine(RFTPEventStr* pEventStruc); // log line to logfile
#endif
and here is the main code:
// FILTERDLL.CPP
// =============
//
// WU_FTP log file format DLL for use with Serv-U v2.2a and higher.
// Enables Serv-U users to create log files in WU_FTP file format.
// The logging settings are read from a file named WULOG.INI.
// Syntax for that file is (example):
//
// ********** WULOG.INI ********
//
// [LOG]
// FileName=c:\serv-u\wulog.txt
//
// *****************************
//
// Author: Rob Beckers
// Date: 11-JUL-97
// Last revision: 11-JUL-97
// Revision nr: 1
//
// Revision history:
//
#include
#include
#include // needed for STL strings
#include // use standard template lib strings, not Borland's
#include
#include
#pragma hdrstop // to make Borland compiler stop including pre-compiled header files
#include "list.h" // used here for simple list management
#include "wulog.h"
// Global variable definitions
LSTUINFO UserList; // list of current user info structures
char LogFile[MAXPATH]; // full path/name of file to log to
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB)
// ******
// Comparison operator for user info structures.
// Is used by the simple list routines.
// ******
{
// equality means the session ID's are the same
return(ArgA.SessionID==ArgB.SessionID);
}
void LoadIniFile(HINSTANCE hInstance)
// ******
// Load .ini file variables
// ******
{
char IniFile[MAXPATH]; // full path of .ini file
// only initialize once
static bool Once=FALSE;
if (Once) return; // already initialized
Once=true; // this is first time, remember
// construct full path of .ini file
GetModuleFileName(hInstance,IniFile,MAXPATH);
char* pEnd=strrchr(IniFile,'\\'); // strip .dll file name
if (pEnd) pEnd[1]='\0';
strcat(IniFile,INIFILE); // create full path .ini name
// get log file name
GetPrivateProfileString(INISECTION,INILOGFILE,"",LogFile,MAXPATH,IniFile);
}
void LogLine(RFTPEventStr* pEventStruc)
// ******
// Log a line to the logfile.
//
// Parameter: pInfoStruc = pointer to event information
// ******
{
// some bullet proofing
if (LogFile[0]=='\0') return; // only if we have a logfile
RUserInfoStr UserInfo;
UserInfo.SessionID=pEventStruc->SessionID;
if (!UserList.Find(UserInfo)) return; // only if we have info on this user
// create time stamp
char CurTime[40];
time_t Count=time(NULL);
strcpy(CurTime,ctime(&Count));
CurTime[24]='\0'; // get rid of newline at end
// log transfer to file
FILE* hFile=fopen(LogFile,"a+t"); // append to file
if (!hFile) return; // problem writing to file
char Direction='o'; // direction flag
if (pEventStruc->Event==EVNT_EndUp) Direction='i';
char Access='a'; // access flag
char User[512]; // user name or anonymous 'password'
if (stricmp(pEventStruc->User,"anonymous")) {
Access='r';
strcpy(User,pEventStruc->User);
}
else strcpy(User,UserInfo.AnonPass.c_str());
fprintf(hFile,"%s %lu %s %lu %s b _ %c %c %s FTP 0 *\n",
CurTime,pEventStruc->Duration/1000L,UserInfo.IPName.c_str(),pEventStruc->Size,
pEventStruc->AuxOne,Direction,Access,User);
fclose(hFile);
}
WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc)
// ******
// Event (hook) handler.
// ******
{
RUserInfoStr UserInfo;
// disect event
switch (pEventStruc->Event) {
// new user connects to server
case EVNT_Connect:
UserInfo.SessionID=pEventStruc->SessionID;
UserInfo.IPName=pEventStruc->ClientIP;
UserList.Add(UserInfo); // add new user to list of users
break;
// user disconnects from server
case EVNT_Close:
UserInfo.SessionID=pEventStruc->SessionID;
UserList.Remove(UserInfo); // remove user info from list
break;
// received symbolic IP name info
case EVNT_IPName:
UserInfo.SessionID=pEventStruc->SessionID;
if (UserList.Find(UserInfo)) { // add IP name to structure in list
UserList.GetCurItemPoint()->IPName=pEventStruc->AuxOne;
}
break;
// catch anonymous' passwords
case EVNT_Login:
if (!stricmp(pEventStruc->User,"anonymous")) {
UserInfo.SessionID=pEventStruc->SessionID;
if (UserList.Find(UserInfo)) { // add 'password' to structure in list
UserList.GetCurItemPoint()->AnonPass=pEventStruc->AuxOne;
}
}
break;
// log file transfers
case EVNT_EndUp:
case EVNT_EndDown:
LogLine(pEventStruc); // log to file
break;
}
return(REVNT_None);
}
BOOL WINAPI DllEntryPoint(HINSTANCE hInstance,DWORD fdwReason,PVOID /*pvReserved*/)
// ******
// Window's DLL entry point.
// Used for initializing list of names-to-block.
// ******
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
LoadIniFile(hInstance); // load .ini file info
break;
}
return(TRUE); // signal success to Windows
}
i would like to code a hook dll for servu (an ftp server), but iam having (shame on me) problems to convert it. most problem for me seems to be the char array inside the structure... i dunno how to convert this in purebasic.
i will post the full source (it is not that much), and would be very glad if someone could convert it, but converting the structures would be a good start aswell... thx in advance...
here comes the header file
// WULOG.H
// =======
//
// WU_FTP logfile format DLL for use with Serv-U v2.2 and higher.
// Code can be found in WULOG.CPP.
//
#ifndef WULOGH // avoid multiple inclusion
#define WULOGH
using namespace std; // to use standard lib identifiers
// Serv-U event definitions
// a copy of the list found in the Serv-U manual
#define EVNT_None 0 // none
#define EVNT_IPName 1 // symbolic IP name available
#define EVNT_Connect 2 // connection was made
#define EVNT_Close 3 // closed connection
#define EVNT_BouncedIP 4 // bounced client because of IP address
#define EVNT_TooMany 5 // bounced user because there are too many
#define EVNT_WrongPass 6 // too many times wrong password
#define EVNT_TimeOut 7 // connection timed out
#define EVNT_Login 8 // use logged in
#define EVNT_StartUp 9 // start upload of file
#define EVNT_EndUp 10 // successfull upload of file
#define EVNT_StartDown 11 // start of download of file
#define EVNT_EndDown 12 // successfull download of file
#define EVNT_AbortUp 13 // aborted upload
#define EVNT_AbortDown 14 // aborted download
#define EVNT_Rename 15 // renamed file/dir
#define EVNT_DelFile 16 // deleted file
#define EVNT_DelDir 17 // deleted dir
#define EVNT_ChgDir 18 // changed working directory
#define EVNT_MakeDir 19 // created directory
// Serv-U event hook definitions
#define EVNT_HookDown 100 // hook for file downloads
#define EVNT_HookUp 101 // hook for file uploads
#define EVNT_HookAppend 102 // hook for append file upload
#define EVNT_HookUnique 103 // hook for unique name upload
#define EVNT_HookRename 104 // hook for rename file/dir
#define EVNT_HookDelFile 105 // hook for delete file
#define EVNT_HookDelDir 106 // hook for delete dir
#define EVNT_HookMkd 107 // hook for make directory
#define EVNT_HookRmd 108 // hook for remove directory
// Serv-U sub-event codes
#define SEVNT_None 0 // no sub-event
#define SEVNT_ErrWrite 1 // problem writing to disk
#define SEVNT_ErrRead 2 // problem reading from disk
#define SEVNT_ErrQuota 3 // insufficient disk quota
#define SEVNT_ErrTOut 4 // packet timed out
#define SEVNT_ErrAbort 5 // user aborted transfer
#define SEVNT_ErrUnknown 6 // unknown error
#define SEVNT_ErrClose 7 // data connection closed unexpectedly
// return codes for hooks
#define REVNT_None 0 // nothing
#define REVNT_Proceed 1 // let event pass
#define REVNT_Abort 2 // stop event
#define REVNT_Suspend 3 // suspend event until decision is made
// event information structure for communications with DLL's
struct RFTPEventStr {
// event info
DWORD Event; // event type
DWORD SubEvent; // sub-event type
// user info
DWORD SessionID; // unique ID of the FTP session
char User[40]; // user name
char ClientIP[16]; // IP number of client
char LocalIP[16]; // IP number the client connected to
// event attributes
DWORD Duration; // duration of events
DWORD Size; // size of object (ie. file)
// hook info
HWND hWindow; // window handle to post decision to
UINT Message; // message to post
char* pReplyText; // pointer to text to send to user
// scratch pad area
char AuxOne[512]; // auxiliary area one
char AuxTwo[512]; // auxiliary area two
};
// user info structure to keep track of sessions
struct RUserInfoStr {
DWORD SessionID; // session ID
string IPName; // IP name of user (if available)
string AnonPass; // anonymous password used to log in (for anonymous users)
};
// some definitions to make life easier
typedef RSimpleList LSTUINFO; // simple linked list of user info structures
#define EXPORT extern "C" __declspec (dllexport) // exported functions declaration header
#define MAXPATH 300 // maximum path length, used for declaring long strings
// text constants
#define INIFILE "wulog.ini" // .ini file name
#define INISECTION "LOG" // .ini file section header used
#define INILOGFILE "FileName" // .ini file logfile line
// function definitions
EXPORT WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc);
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB);
void LoadIniFile(HINSTANCE hInst); // process .ini file
void LogLine(RFTPEventStr* pEventStruc); // log line to logfile
#endif
and here is the main code:
// FILTERDLL.CPP
// =============
//
// WU_FTP log file format DLL for use with Serv-U v2.2a and higher.
// Enables Serv-U users to create log files in WU_FTP file format.
// The logging settings are read from a file named WULOG.INI.
// Syntax for that file is (example):
//
// ********** WULOG.INI ********
//
// [LOG]
// FileName=c:\serv-u\wulog.txt
//
// *****************************
//
// Author: Rob Beckers
// Date: 11-JUL-97
// Last revision: 11-JUL-97
// Revision nr: 1
//
// Revision history:
//
#include
#include
#include // needed for STL strings
#include // use standard template lib strings, not Borland's
#include
#include
#pragma hdrstop // to make Borland compiler stop including pre-compiled header files
#include "list.h" // used here for simple list management
#include "wulog.h"
// Global variable definitions
LSTUINFO UserList; // list of current user info structures
char LogFile[MAXPATH]; // full path/name of file to log to
int operator==(const RUserInfoStr& ArgA,const RUserInfoStr& ArgB)
// ******
// Comparison operator for user info structures.
// Is used by the simple list routines.
// ******
{
// equality means the session ID's are the same
return(ArgA.SessionID==ArgB.SessionID);
}
void LoadIniFile(HINSTANCE hInstance)
// ******
// Load .ini file variables
// ******
{
char IniFile[MAXPATH]; // full path of .ini file
// only initialize once
static bool Once=FALSE;
if (Once) return; // already initialized
Once=true; // this is first time, remember
// construct full path of .ini file
GetModuleFileName(hInstance,IniFile,MAXPATH);
char* pEnd=strrchr(IniFile,'\\'); // strip .dll file name
if (pEnd) pEnd[1]='\0';
strcat(IniFile,INIFILE); // create full path .ini name
// get log file name
GetPrivateProfileString(INISECTION,INILOGFILE,"",LogFile,MAXPATH,IniFile);
}
void LogLine(RFTPEventStr* pEventStruc)
// ******
// Log a line to the logfile.
//
// Parameter: pInfoStruc = pointer to event information
// ******
{
// some bullet proofing
if (LogFile[0]=='\0') return; // only if we have a logfile
RUserInfoStr UserInfo;
UserInfo.SessionID=pEventStruc->SessionID;
if (!UserList.Find(UserInfo)) return; // only if we have info on this user
// create time stamp
char CurTime[40];
time_t Count=time(NULL);
strcpy(CurTime,ctime(&Count));
CurTime[24]='\0'; // get rid of newline at end
// log transfer to file
FILE* hFile=fopen(LogFile,"a+t"); // append to file
if (!hFile) return; // problem writing to file
char Direction='o'; // direction flag
if (pEventStruc->Event==EVNT_EndUp) Direction='i';
char Access='a'; // access flag
char User[512]; // user name or anonymous 'password'
if (stricmp(pEventStruc->User,"anonymous")) {
Access='r';
strcpy(User,pEventStruc->User);
}
else strcpy(User,UserInfo.AnonPass.c_str());
fprintf(hFile,"%s %lu %s %lu %s b _ %c %c %s FTP 0 *\n",
CurTime,pEventStruc->Duration/1000L,UserInfo.IPName.c_str(),pEventStruc->Size,
pEventStruc->AuxOne,Direction,Access,User);
fclose(hFile);
}
WORD CALLBACK HandleEventHook(RFTPEventStr* pEventStruc)
// ******
// Event (hook) handler.
// ******
{
RUserInfoStr UserInfo;
// disect event
switch (pEventStruc->Event) {
// new user connects to server
case EVNT_Connect:
UserInfo.SessionID=pEventStruc->SessionID;
UserInfo.IPName=pEventStruc->ClientIP;
UserList.Add(UserInfo); // add new user to list of users
break;
// user disconnects from server
case EVNT_Close:
UserInfo.SessionID=pEventStruc->SessionID;
UserList.Remove(UserInfo); // remove user info from list
break;
// received symbolic IP name info
case EVNT_IPName:
UserInfo.SessionID=pEventStruc->SessionID;
if (UserList.Find(UserInfo)) { // add IP name to structure in list
UserList.GetCurItemPoint()->IPName=pEventStruc->AuxOne;
}
break;
// catch anonymous' passwords
case EVNT_Login:
if (!stricmp(pEventStruc->User,"anonymous")) {
UserInfo.SessionID=pEventStruc->SessionID;
if (UserList.Find(UserInfo)) { // add 'password' to structure in list
UserList.GetCurItemPoint()->AnonPass=pEventStruc->AuxOne;
}
}
break;
// log file transfers
case EVNT_EndUp:
case EVNT_EndDown:
LogLine(pEventStruc); // log to file
break;
}
return(REVNT_None);
}
BOOL WINAPI DllEntryPoint(HINSTANCE hInstance,DWORD fdwReason,PVOID /*pvReserved*/)
// ******
// Window's DLL entry point.
// Used for initializing list of names-to-block.
// ******
{
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
LoadIniFile(hInstance); // load .ini file info
break;
}
return(TRUE); // signal success to Windows
}