WarFsys.h
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:15k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : WarFsys.h
- // PURPOSE : Header file for all file systems used by the War daemons
- // PROGRAM :
- // DATE : March 11 1997
- // AUTHOR : Jarle Aase
- // ---
- //
- //
- // REVISION HISTORY
- //
- #ifndef __WARFSYSH
- #define __WARFSYSH
- #ifndef __UNIXFSYSTYPESH
- #include "unixfsystypes.h"
- #endif
- #ifdef __WARDAEMONH
- #ifndef __USERH
- #include "user.h"
- #endif
- #endif
- class CWarFile;
- #define HANDLE_PENDING (HANDLE)0xfffffffe
- /////////////////////////////////////////////////////////////////////////////
- // Simple file system
- class DLL_WAR_SOFTWARE_ CFileInfo
- {
- public:
- DWORD m_Flags;
- DWORD m_DOSflags;
- USER m_User;
- USER m_Group;
- int m_Inode;
- int m_Links;
- CString m_Comment;
- CString m_Name;
- BOOL m_Hide; // Dont show in dir listings (used by ls to hide . files)
- FILETIME m_CreationTime;
- FILETIME m_LastModifyTime;
- FLEN m_FileSize;
- DWORD m_DLcount;
- DWORD m_SpecialNewFilePerms;
- USER *m_pMoreUsers; // Array of more users with class permission
- public:
- CFileInfo();
- ~CFileInfo();
- virtual LPCSTR FileName() const {return m_Name;}
- virtual CString MakeFileNameASCII();
- virtual BOOL Hide(int State);
- FLEN GetFileLength() {return m_FileSize;}
- FLEN GetFileBlocks() {return m_FileSize / (FLEN)512;}
- int GetInode();
- int GetLinks();
- const LPFILETIME GetModifyTime() const {return (const LPFILETIME)&m_LastModifyTime;}
- const LPFILETIME GetAccessTime() const {return (const LPFILETIME)&m_LastModifyTime;}
- const LPFILETIME GetCreationTime() const {return (const LPFILETIME)&m_CreationTime;}
- const LPFILETIME GetLastModeTime() const {return (const LPFILETIME)&m_LastModifyTime;}
- BOOL IsDirectory() {return (m_Flags & NODE_DIR);}
- BOOL IsReadOnly() {return (m_Flags & NODE_READONLY);}
- int GetFileNameLen() {return m_Name.GetLength();}
- DWORD GetPermissions() {return m_Flags;}
- LPCSTR GetComment() {return m_Comment.IsEmpty() ? (LPCSTR)NULL : (LPCSTR)m_Comment;}
- USER GetUser() {return m_User; }
- USER GetGroup() {return m_Group; }
- DWORD GetDLCount() {return m_DLcount; }
- DWORD GetSpecialNewFilePerms() {return m_SpecialNewFilePerms;}
- #ifdef __WARDAEMONH
- // Server support (this is real bad coding!!)
- LPCSTR CFileInfo::GetUserName(CString& cBuf) const
- {
- if (!m_User || !CUsr::FindUser(m_User,cBuf))
- return "root";
- return (LPCSTR)cBuf;
- }
- LPCSTR CFileInfo::GetGroupName(CString& cBuf) const
- {
- if (!m_Group || !CUsr::FindUser(m_Group,cBuf))
- return "root";
- return (LPCSTR)cBuf;
- }
- #else
- LPCSTR CFileInfo::GetUserName(CString& cBuf) const {return "root"; }
- LPCSTR CFileInfo::GetGroupName(CString& cBuf) const {return "root"; }
- #endif // __WARDAEMONH
- };
- class DLL_WAR_SOFTWARE_ CFileInfoList
- {
- public:
- CLinkedList m_List;
- int m_MaxCols;
- CLinkedListItem *m_Prev;
- CString m_FullPath;
- public:
- CFileInfoList();
- ~CFileInfoList();
- void Add(CFileInfo *Node);
- CFileInfo *GetNext(CFileInfo *Current);
- void Sort(int (*SortFunc)(const void *, const void *));
- BOOL ListRaw(CString& cReturnBuf, DWORD Flags = 0);
- };
- // File system driver at the physical layer
- class DLL_WAR_SOFTWARE_ CFileSystemTemplate
- {
- public:
- SMEM Name; // Name of file system
- SMEM LoginName; // LPCSTR network login name
- SMEM LoginPwd; // LPCSTR network login password
- SMEM NetPath; // LPCSTR physical network path in DOS format
- DWORD Flags; // Bitflags
- DWORD NumOpenFiles;
- DWORD NumOpenHandles;
- FLEN FreeSpace; // Bytes available on system
- enum
- {
- COPY_TO_TEMP = 0x00000001, // Copy files to a temp dir
- NETLOGIN = 0x00000002, // Network - perform login
- ISOPEN = 0x00000004, // File system is opened
- ISVIRTUAL = 0x00000008, // Virtual file system, no IO
- READONLY = 0x00000010, // Read only file system
- };
- // IO calll
- BOOL (*CreateDirectory)(LPCTSTR Path);
- BOOL (*RemoveDirectory)(LPCTSTR lpPathName);
- BOOL (*DeleteFile)(LPCSTR Path);
- FLEN (*GetDiskFreeSpace)(LPCSTR Path);
- BOOL (*MoveFile)(LPCTSTR ExistingFileName, LPCTSTR NewFileName);
- void (*CloseHandle)(HANDLE hVal);
- HANDLE (*FindFirstFile)(LPCTSTR lpFileName, CFileInfo& FileInfo);
- BOOL (*FindNextFile)(HANDLE hVal, CFileInfo& FileInfo);
- void (*FindClose)(HANDLE hVal);
- DWORD (*GetFileAttributes)(LPCTSTR lpFileName );
- UINT (*GetDriveType)(LPCTSTR lpRootPathName);
- FLEN (*GetFileSize)(HANDLE hFile);
- FLEN (*Seek)(HANDLE hFile, FLEN flOfs, DWORD dwFrom);
- HANDLE (*GetSecurityHandleFromFindHandle)(HANDLE hFind);
- HANDLE (*CreateFile)(
- LPCTSTR lpFileName, // pointer to name of the file
- DWORD dwDesiredAccess, // access (read-write) mode
- DWORD dwShareMode, // share mode
- LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security descriptor
- DWORD dwCreationDistribution, // how to create
- DWORD dwFlagsAndAttributes, // file attributes
- HANDLE hTemplateFile // handle to file with attributes to copy
- );
- BOOL (*ReadFile)(
- HANDLE hFile, // handle of file to read
- LPVOID lpBuffer, // address of buffer that receives data
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPDWORD lpNumberOfBytesRead, // address of number of bytes read
- LPOVERLAPPED lpOverlapped // address of structure for data
- );
- BOOL (*ReadFileEx)(
- HANDLE hFile, // handle of file to read
- LPVOID lpBuffer, // address of buffer
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPOVERLAPPED lpOverlapped, // address of offset
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // address of completion routine
- );
- BOOL (*WriteFile)(
- HANDLE hFile, // handle to file to write to
- LPCVOID lpBuffer, // pointer to data to write to file
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
- LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped I/O
- );
- BOOL (*WriteFileEx)(
- HANDLE hFile, // handle to output file
- LPCVOID lpBuffer, // pointer to input buffer
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPOVERLAPPED lpOverlapped, // pointer to async. i/o data
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // ptr. to completion routine
- );
- };
- //////////////////////////////////////////////////////////////////
- // User level interface. Handles all stuff in regard with
- // the daemon.
- struct CREATE_HDR
- {
- // Path goes in CUserFsys::m_FsysPath1
- DWORD HdrLen;
- DWORD dwDesiredAccess; // access (read-write) mode
- DWORD dwShareMode; // share mode
- LPSECURITY_ATTRIBUTES lpSecurityAttributes; // pointer to security descriptor
- DWORD dwCreationDistribution; // how to create
- DWORD dwFlagsAndAttributes; // file attributes
- HANDLE hTemplateFile; // handle to file with attributes to copy
- DWORD Flags;
- LPARAM lParam; // Callback data
- void (*Callback)(CWarFile *, BOOL, LPARAM); // Callback function
- CWarFile *pFile;
- };
- class DLL_WAR_SOFTWARE_ CUserFsys
- {
- public:
- CUserFsys(LPVOID *pRef = NULL);
- ~CUserFsys();
- public:
- virtual BOOL Create(
- LPCSTR Roots,
- LPCSTR Home,
- USER User,
- USER Class,
- LPCSTR Name = NULL,
- DWORD Umask = 0,
- USER AssignTo = INVALID_USER_VALUE);
- virtual void Logout();
- virtual BOOL CreateFile(LPCSTR Path, CREATE_HDR *pHdr);
- static BOOL StartFileSystem(LPCSTR IniPath = NULL);
- void LogMsg(int flag, LPCSTR Format, ...);
- static void CloseFileSystem(); // Master - called to shut down
- static BOOL FsysIsStarted() {return m_hFsys != NULL;}
- virtual BOOL BldFileInfoList(CFileInfoList& FileList, LPCSTR Path, BOOL ListDir);
- virtual BOOL ChDir(LPCSTR Path);
- virtual BOOL ChMod(CCmdArgs& Args);
- virtual void OnCallback(LPARAM lParam);
- HWND GetFsys_hWnd() {return m_Fsys_hWnd;}
- virtual BOOL FsysStat();
- virtual BOOL CreateDirectory(LPCSTR FsysPath);
- virtual BOOL DeleteDirectory(LPCSTR FsysPath);
- virtual BOOL DeleteFile(LPCSTR FsysPath);
- virtual BOOL DeleteGeneric(LPCSTR FsysPath);
- virtual BOOL LinkFile(LPCSTR FromPath, LPCSTR ToPath);
- virtual BOOL MoveFile(LPCSTR FromPath, LPCSTR ToPath);
- virtual BOOL Stat(LPCSTR FsysPath);
- protected:
- BOOL ProcessRequest(int Type, WPARAM wParam, LPARAM lParam);
- static CLinkedList m_ObjectList; // CUserFsys
- static HINSTANCE m_hFsys;
- static HWND m_Fsys_hWnd;
- public:
- USER m_User;
- USER m_Class;
- USER m_AssignTo;
- DWORD m_Umask;
- unsigned m_IsAdmin : 1; // Is administrator - override security
- unsigned m_IsSystem : 1; // Is System - override everything :-)
- unsigned m_CallbackPending : 1; // Can not be deleted yet
- unsigned m_IsZombie : 1; // the socket is dead.
- unsigned m_FsysErrno : 8; // File system error code (NOT DOS error)
- DWORD m_DOSErrno; // DOS error number
- int m_LastReqType; // Callback code
- LPARAM m_FsysLparam; // Used internally by the File system
- CREATE_HDR m_CreateHdr; // Used when a file is created/opeed
- CString m_FsysPath1; // Used to pass data to/from fsys
- CString m_FsysPath2; // Used to pass data to/from fsys
- CString m_FsysPath3; // Used to pass data to/from fsys
- CString m_Output;
- CCmdArgs m_Args; // Used by UNIX derived functions
- FLEN m_FileLen; // Used by STAT
- FILETIME m_FileTime; // Used by STAT
- DWORD m_FilePerms; // Used by STAT
- HANDLE m_hNTsec; // Use NT security if present
- CString m_CWD; // Current directory
- CString m_DOSCWD; // Physical CWD
- CString m_Home;
- CString m_Name; // Visual name of user
- CLinkedList m_OpenFiles; // CWarFsysFileHandle
- //CLinkedList m_OpenFinds; // CWarFsysFindHandle
- protected:
- LPVOID *m_pRef;
- // Callback functions
- protected:
- virtual BOOL SetOnHold(); // Called when a callback needs to wait...
- // Return FALSE to abort the operation
- virtual void ReleaseHold(); // Release hold state - callback is not called.
- virtual void CheckForZombie(); // Release resources and throw an execpion
- virtual BOOL OnCreate(int nErrorCode); // Called after Create()
- virtual BOOL OnChdir(int nErrorCode);
- virtual BOOL OnPrpCmdLine(int nErrorCode);
- virtual BOOL OnList(int nErrorCode);
- virtual BOOL OnCreateFile(int nErrorCode);
- virtual BOOL OnWlist(int nErrorCode);
- virtual BOOL OnChmod(int nErrorCode);
- virtual BOOL OnFsysStat(int nErrorCode);
- virtual BOOL OnCreateDirectory(int nErrorCode);
- virtual BOOL OnDeleteDirectory(int nErrorCode);
- virtual BOOL OnDeleteFile(int nErrorCode);
- virtual BOOL OnDeleteGeneric(int nErrorCode);
- virtual BOOL OnLinkFile(int nErrorCode);
- virtual BOOL OnMoveFile(int nErrorCode);
- virtual BOOL OnStat(int nErrorCode);
- };
- // Class for file IO
- class DLL_WAR_SOFTWARE_ CWarFile : public CObject
- {
- public:
- CWarFile(CUserFsys *pFsys = NULL);
- void Destroy(); // Public destructor
- protected:
- ~CWarFile();
- public:
- // Data members
- HANDLE m_hFile; // Handle to file
- CFileSystemTemplate *m_DEV; // Device driver
- CString m_Path; // Open path
- CUserFsys *m_pFsys;
- int m_CallbackPending;
- int m_ProtectFromDelete;
- BOOL m_IsZombie;
- SMEM m_smNode;
- // IO Calls
- HANDLE GetOSHandle() {return m_hFile;}
- void Close();
- DWORD GetFileAttributes();
- UINT GetDriveType();
- FLEN GetFileSize();
- FLEN Seek(FLEN lsOfs, UINT nFrom );
- BOOL IsOpen() {return ((m_hFile != INVALID_HANDLE_VALUE)
- && (m_hFile != HANDLE_PENDING));}
- BOOL CallbackIsPending() {return m_hFile == (HANDLE)HANDLE_PENDING; }
- BOOL ProcessFlagsLocal(DWORD Flags);
- BOOL Create(
- LPCTSTR lpFileName, // pointer to name of the file
- DWORD dwDesiredAccess, // access (read-write) mode
- DWORD dwShareMode, // share mode
- LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security descriptor
- DWORD dwCreationDistribution, // how to create
- DWORD dwFlagsAndAttributes, // file attributes
- HANDLE hTemplateFile, // handle to file with attributes to copy
- DWORD Flags, // Special flags
- LPARAM lParam, // Callback data
- void (*Callback)(CWarFile *, BOOL, LPARAM) // Callback function
- );
- BOOL Read(
- LPVOID lpBuffer, // address of buffer that receives data
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPDWORD lpNumberOfBytesRead, // address of number of bytes read
- LPOVERLAPPED lpOverlapped // address of structure for data
- );
- BOOL ReadEx(
- LPVOID lpBuffer, // address of buffer
- DWORD nNumberOfBytesToRead, // number of bytes to read
- LPOVERLAPPED lpOverlapped, // address of offset
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // address of completion routine
- );
- BOOL Write(
- LPCVOID lpBuffer, // pointer to data to write to file
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
- LPOVERLAPPED lpOverlapped // pointer to structure needed for overlapped I/O
- );
- BOOL WriteEx(
- LPCVOID lpBuffer, // pointer to input buffer
- DWORD nNumberOfBytesToWrite, // number of bytes to write
- LPOVERLAPPED lpOverlapped, // pointer to async. i/o data
- LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine // ptr. to completion routine
- );
- enum // Flags
- {
- UNIQUE_NAME = 0x00000001,
- WRITE_LOCK = 0x00000002,
- };
- };
- enum // File system messages
- {
- FSM_CALLBACK = WM_USER,
- FSM_CREATEFILE,
- FSM_CREATEUSER, // Called by CUserFsys::Create()
- FSM_PRPCMDLINE, // Prepare command line
- FSM_LIST,
- FSM_CHDIR,
- FSM_CLOSEFILE, // Notification, no callback
- FSM_CHMOD,
- FSM_WLST, // War native list, place output in m_FsysPath2
- FSM_FSYSSTAT, // Give information
- FSM_CREATEDIR, // Create directory
- FSM_DELEDIR, // Delete directory
- FSM_DELEFILE, // Delete file
- FSM_DELE, // Delete file or directory
- FSM_LINK, // Soft link a file
- FSM_MOVE, // Rename (or) move a file. Works on files and directories.
- FSM_QUIT, // Quit a fsys thread
- FSM_STAT, // Return filelength and filedate
- };
- enum // File system eror messages
- {
- FSE_NO_ERROR,
- FSE_UNKNOWN_CALL,
- FSE_NO_ROOTPATH,
- FSE_BAD_ROOTPATH,
- FSE_BAD_PATH,
- FSE_PERMISSION_DENIED,
- FSE_PATH_NOT_FOUND,
- FSE_UNIX_ERROR,
- FSE_INVALID
- };
- #endif __WARFSYSH