RemoteAdmin.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:25k
源码类别:
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 : RemoteAdmin.cpp
- // PURPOSE : Remote administration daemon interface
- // PROGRAM :
- // DATE : Nov. 4 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #include "stdafx.h"
- #include "WarDaemon.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ////////////////////////////////////////////////////////////////////
- // Admin Command parser
- enum // Token ID's
- {
- TOK_QUIT = TOK_START_TAB, TOK_LIST, TOK_OPTS, TOK_OPT, TOK_SET, TOK_USER, TOK_USRS,
- TOK_CREA, TOK_DELE, TOK_SHOW, TOK_ON, TOK_OFF, TOK_EVNT, TOK_STAT, TOK_VER, TOK_GET,
- TOK_FIND, TOK_SHDN, TOK_GROUP, TOK_CLASS, TOK_VSERVER, TOK_RENAME, TOK_DIR, TOK_CHMOD,
- TOK_GOONL, TOK_GOOFFLN, TOK_RESTART, TOK_EXTENSIONS, TOK_DLL,
- };
- static STokenTab BaseTokens[] =
- {
- {TOK_QUIT, "QUIT" },
- {TOK_LIST, "LIST" },
- {TOK_SHOW, "SHOW" },
- {TOK_SET, "SET" },
- {TOK_GET, "GET" },
- {TOK_OPTS, "OPTIONS"},
- {TOK_OPT, "OPTION" },
- {TOK_USER, "USER" },
- {TOK_USRS, "USERS" },
- {TOK_CREA, "CREATE" },
- {TOK_DELE, "DELETE" },
- {TOK_EVNT, "EVENTS" },
- {TOK_ON, "ON", },
- {TOK_OFF, "OFF" },
- {TOK_STAT, "STATUS"},
- {TOK_VER, "VERSION"},
- {TOK_FIND, "FIND"},
- {TOK_SHDN, "SHUTDOWN"},
- {TOK_GROUP, "GROUP"},
- {TOK_CLASS, "CLASS"},
- {TOK_VSERVER,"VSERVER"},
- {TOK_RENAME, "RENAME"},
- {TOK_DIR, "DIR"},
- {TOK_CHMOD, "CHMOD"},
- {TOK_GOONL, "GOONLINE"},
- {TOK_GOOFFLN,"GOOFFLINE"},
- {TOK_RESTART,"RESTART"},
- {TOK_EXTENSIONS,"EXTENSIONS"},
- {TOK_DLL, "DLL"},
- {TOK_INVALID, "" }
- };
- enum // Commands recognized on this level
- {
- CMD_QUIT = CMD_START_TREE, CMD_LOPT, CMD_SOPT, CMD_LUSR, CMD_CRUS, CMD_SHUS, CMD_STUS,
- CMD_EVON, CMD_EVOF, CMD_STAT, CMD_VER, CMD_GOPT, CMD_FUNA, CMD_FUNO, CMD_GUOP, CMD_SHDN,
- CMD_LUST, CMD_CRGR, CMD_CRCL, CMD_CRVS, CMD_DELUS, CMD_RENUS, CMD_LDIR, CMD_CHMOD,
- CMD_GONL, CMD_GOOF, CMD_RSTR, CMD_LIEX, CMD_GETEXT, CMD_GETDLL, CMD_SETDLL,
- };
- static SCommandTree ListUserCmds[] =
- {
- {TOK_INT, CMD_LUST, PROCESS, 0, NULL, 0, LEX_WANT_STRING, "LIST USERS <type> <pattern>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree ListCmds[] =
- {
- {TOK_OPTS, CMD_LOPT, PROCESS, 0, NULL, 0, LEX_WANT_STRING, "LIST OPTIONS (list option groups)" },
- {TOK_USRS, CMD_INVALID, PROCESS, CMDF_PARAMETER, ListUserCmds, ' ', LEX_WANT_INT, "" },
- {TOK_USRS, CMD_LUSR, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "LIST USERS <pattern>" },
- {TOK_DIR, CMD_LDIR, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "LIST DIR <path>" },
- {TOK_EXTENSIONS, CMD_LIEX, PROCESS, 0, NULL, 0, 0, "LIST EXTENSIONS"},
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree EventCmds[] =
- {
- {TOK_ON, CMD_EVON, PROCESS, 0, NULL, 0, 0, "SET EVENTS n ON (Torn on events)" },
- {TOK_OFF, CMD_EVOF, PROCESS, 0, NULL, 0, 0, "SET EVENTS n OFF (Turns off events)" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree EventNum[] =
- {
- {TOK_INT, CMD_INVALID, PROCESS, 0, EventCmds, 0, LEX_WANT_CMD, "" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree SetCmds[] =
- {
- {TOK_OPT, CMD_SOPT, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "SET OPTION <optgrp/option=value>" },
- {TOK_USER, CMD_STUS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "SET USER <user/option=value>" },
- {TOK_EVNT, CMD_INVALID, PROCESS, 0, EventNum, ' ', LEX_WANT_INT, "SET EVENTS n <ON or OFF>" },
- {TOK_DLL, CMD_SETDLL, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "SET DLL <name> = 1 | 0" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree GetUserCmds[] =
- {
- {TOK_OPT, CMD_GUOP, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "GET USER OPTION <User/option>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree GetCmds[] =
- {
- {TOK_OPT, CMD_GOPT, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "GET OPTION <optgrp/option>" },
- {TOK_USER, CMD_INVALID, PROCESS, CMDF_PARAMETER, GetUserCmds, ' ', LEX_WANT_CMD, "GET USER <what>" },
- {TOK_EXTENSIONS, CMD_LIEX, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "GET EXTENSION <name>" },
- {TOK_DLL, CMD_GETDLL, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "GET DLL <name>"},
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree CreaCmds[] =
- {
- {TOK_USER, CMD_CRUS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "CREATE USER name" },
- {TOK_GROUP, CMD_CRGR, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "CREATE GROUP name" },
- {TOK_CLASS, CMD_CRCL, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "CREATE CLASS name" },
- {TOK_VSERVER, CMD_CRVS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "CREATE VSERVER name" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree FunaCmds[] =
- {
- {TOK_USER, CMD_FUNA, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_INT, "FIND USER <ID> <type>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree FindCmds[] =
- {
- {TOK_USER, CMD_FUNO, PROCESS, CMDF_PARAMETER, NULL, ' ', LEX_WANT_INT, "FIND USER <number>" },
- {TOK_USER, CMD_INVALID, PROCESS, CMDF_PARAMETER, FunaCmds, ' ', LEX_WANT_STRING, "FIND USER <ID> <type>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree ShowCmds[] =
- {
- {TOK_USER, CMD_SHUS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "SHOW USER name" },
- {TOK_VER, CMD_VER , PRELOGIN, 0, NULL, 0, LEX_WANT_STRING, "SHOW VERSION (show server version)" },
- {TOK_STAT, CMD_STAT, PROCESS, 0, NULL, 0, LEX_WANT_STRING, "SHOW STATUS (show server status)" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree DeleCmds[] =
- {
- {TOK_USER, CMD_DELUS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "DELTE USER <num>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree RenameUserCmds[] =
- {
- {TOK_USER, CMD_RENUS, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "RENAME USER <num> <new name>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- static SCommandTree RenameCmds[] =
- {
- {TOK_USER, CMD_INVALID, PROCESS, CMDF_PARAMETER, RenameUserCmds, ' ', LEX_WANT_STRING, "RENAME USER <num> <new name>" },
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- // Command tree
- static SCommandTree BaseCmds[] =
- {
- {TOK_QUIT, CMD_QUIT, PRELOGIN, 0, NULL, ' ', 0, "QUIT (end session)" },
- {TOK_LIST, CMD_INVALID, PROCESS, CMDF_PARAMETER, ListCmds, ' ', LEX_WANT_CMD, "LIST <what>" },
- {TOK_SET, CMD_INVALID, PROCESS, CMDF_PARAMETER, SetCmds, ' ', LEX_WANT_CMD, "SET <what>" },
- {TOK_GET, CMD_INVALID, PROCESS, CMDF_PARAMETER, GetCmds, ' ', LEX_WANT_CMD, "GET <what>" },
- {TOK_CREA, CMD_INVALID, PROCESS, CMDF_PARAMETER, CreaCmds, ' ', LEX_WANT_CMD, "CREATE <what>" },
- {TOK_DELE, CMD_INVALID, PROCESS, CMDF_PARAMETER, DeleCmds, ' ', LEX_WANT_CMD, "DELETE <what>" },
- {TOK_RENAME, CMD_INVALID, PROCESS, CMDF_PARAMETER, RenameCmds, ' ', LEX_WANT_CMD, "DELETE <what>" },
- {TOK_SHOW, CMD_INVALID, PROCESS, CMDF_PARAMETER, ShowCmds, ' ', LEX_WANT_CMD, "SHOW <what>" },
- {TOK_FIND, CMD_INVALID, PROCESS, CMDF_PARAMETER, FindCmds, ' ', LEX_WANT_CMD, "FIND <what>" },
- {TOK_SHDN, CMD_SHDN, PROCESS, 0, NULL, ' ', LEX_WANT_BOOL, "SHUTDOWN (terminate the server)" },
- {TOK_CHMOD, CMD_CHMOD, PROCESS, CMDF_PARAMETER, NULL, 0, LEX_WANT_STRING, "CHMOD" },
- {TOK_GOONL, CMD_GONL, PROCESS, 0, NULL, ' ', LEX_WANT_CMD, "GOONLINE (go online)"},
- {TOK_GOOFFLN, CMD_GOOF, PROCESS, 0, NULL, ' ', LEX_WANT_CMD, "GOOFFLINE (go offline)"},
- {TOK_RESTART, CMD_RSTR, PROCESS, 0, NULL, ' ', LEX_WANT_CMD, "RESTART (Restart server)"},
- {TOK_INVALID, CMD_INVALID, 0, 0, NULL, 0, 0, NULL}
- };
- CAdminParser::CAdminParser()
- {
- m_Commands = (SCommandTree *) BaseCmds;
- m_Tokens = (STokenTab *) BaseTokens;
- }
- ///////////////////////////////////////////////////////////////////////////////////////
- // CDaemonMaintananceSocket
- IMPLEMENT_DYNAMIC(CDaemonMaintananceSocket, CTextSock);
- CDaemonMaintananceSocket::CDaemonMaintananceSocket()
- {
- // Increase login counter
- m_pFsys = NULL;
- CDaemonStatusSvr::IncOperatorCnt(TRUE);
- }
- CDaemonMaintananceSocket::~CDaemonMaintananceSocket()
- {
- if (m_pFsys)
- {
- m_pFsys->Logout();
- }
- CDaemonStatusSvr::IncOperatorCnt(FALSE);
- }
- BOOL CDaemonMaintananceSocket::OnCommand(LPCSTR Text)
- {
- if (!CTextSock::OnCommand(Text))
- return FALSE;
- BOOL Rval = TRUE;
- CCmdArgs Args;
- int CmdID;
- CString cBuf;
- int ival;
- USER MyUser;
- // EXT module
- if (PrcSockExt(CSock::iOnCommand,0,(WPARAM)0,(LPARAM)&Text))
- return TRUE;
- // Login
- switch(m_State)
- {
- case PRELOGIN: // We want username
- SendCtrlMsg(331,"Password: ", FALSE, FALSE);
- if (m_LocalEcho)
- m_LocalEcho = '*';
- m_State = GOTNAME;
- m_ArgSave = Text;
- break;
- case GOTNAME: // We want password
- if (((m_User = CUsr::Login(LT_REMOTE, m_ArgSave, Text, this)) == 0)
- || !CUsr::IsAdmin(m_User))
- {
- SendCtrlMsg(521,"Goodbye. Connection closed.");
- delete this;
- return FALSE;
- }
- m_State = PROCESS;
- SendMsg(230,"Logged in.");
- NotifyLogin(ENL_UPDATE, "");
- // Password is OK. Move on to Process..
- goto prompt;
- case PROCESS:
- // Parse command
- CmdID = m_Parser.ParseCmd(Text,Args, m_State);
- switch(CmdID)
- {
- case CMD_LIEX: // LIST EXTENSIONS
- SendMsg(200,"%s", CAPIHandler::ListAll());
- break;
- case CMD_GETDLL: // Get a dll from the server
- {
- LPCSTR p = Args.Arg(2);
- if (p && (p = strrchr(p, '.')))
- {
- if (!stricmp(p,".dll"))
- {
- if (SendFile(NULL, Args.Arg(2)))
- break; // SendFile will reply
- }
- }
- }
- LogMsg(LOGF_FILEACC,"CMD_GETDLL - File send '%s' failed.", Args.Arg(2));
- SendMsg(550, "File send failed");
- break;
- case CMD_SETDLL: // Enable/disable dll
- if (CAPIHandler::GetPtr() && CAPIHandler::GetPtr()->EnableDll(Args.Arg(2)))
- SendMsg(200, "DLL command OK.");
- else
- SendMsg(550, "DLL command failed.");
- break;
- case CMD_QUIT:
- SendMsg(221,"Goodbye. Connection closed.");
- LogMsg(LOGF_INOUT,"User from %s has logged off.", m_PeerName);
- delete this;
- return FALSE;
- break;
- case CMD_LOPT: // list options
- if (COptions::ListOptions(Args.m_argc > 2 ? Args.Arg(2) : "",cBuf))
- SendMsg(200, cBuf);
- else
- SendMsg(550,"Unknown option group.");
- break;
- case CMD_SOPT: // Set option
- if (Args.m_argc != 3)
- SendMsg(501,"Missing required parameter.");
- else if (COptions::SetOption(Args[2], TRUE))
- SendMsg(200, "OK");
- else
- SendMsg(550,"Failed to set option. (syntax: Group/Option=new value)");
- break;
- case CMD_GOPT: // Get option
- if (Args.m_argc != 3)
- SendMsg(501,"Missing required parameter.");
- else if (COptions::GetOption(Args[2], cBuf, TRUE))
- SendMsg(200, "%s", cBuf);
- else
- SendMsg(550,"Failed to get option. (syntax: Group/Option)");
- break;
- case CMD_LUSR: // List users
- if (CUsr::ListUsers(UT_USER, Args.m_argc > 2 ? Args.Arg(2) : "",cBuf, m_LocalEcho))
- SendCtrlMsg(200, cBuf);
- else
- SendCtrlMsg(550,"No match.");
- break;
- case CMD_LUST: // List users (with type)
- if (CUsr::ListUsers(
- atoi(Args.Arg(2)), Args.m_argc > 3 ? Args.Arg(3) : "",cBuf, m_LocalEcho))
- SendCtrlMsg(200, cBuf);
- else
- SendCtrlMsg(550,"No match.");
- break;
- case CMD_CRUS: // Create user name
- if ((ival = CUsr::AddUser(UT_USER,Args.Arg(2))) == 0)
- SendMsg(550,"Failed to create user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User %d <%s> created. Account is not activated.", ival, Args.Arg(2));
- break;
- case CMD_CRGR: // Create group name
- if ((ival = CUsr::AddUser(UT_GROUP,Args.Arg(2))) == 0)
- SendMsg(550,"Failed to create user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User %d <%s> created. Account is not activated.", ival, Args.Arg(2));
- break;
- case CMD_CRCL: // Create class name
- if ((ival = CUsr::AddUser(UT_CLASS,Args.Arg(2))) == 0)
- SendMsg(550,"Failed to create user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User %d <%s> created. Account is not activated.", ival, Args.Arg(2));
- break;
- case CMD_CRVS: // Create virtual server name
- if ((ival = CUsr::AddUser(UT_SYSTEM,Args.Arg(2))) == 0)
- SendMsg(550,"Failed to create user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User %d <%s> created. Account is not activated.", ival, Args.Arg(2));
- break;
- case CMD_DELUS: // Delete user
- if (!CUsr::DeleteUser(Args.Arg(2)))
- SendMsg(550,"Failed to delete user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User <%s> deleted.", Args.Arg(2));
- break;
- case CMD_RENUS: // Rename user
- if (!CUsr::RenameUser(Args.Arg(2), Args.Arg(3)))
- SendMsg(550,"Failed to Rename user <%s>.", Args.Arg(2));
- else
- SendMsg(200,"User <%s>.", Args.Arg(2));
- break;
- case CMD_SHUS: // Show user
- if (Args.m_argc != 3)
- SendMsg(501,"Missing required parameter.");
- else if (CUsr::ListUserParams(UT_USER,Args.Arg(2), cBuf))
- SendMsg(200, cBuf);
- else
- SendMsg(550,"User <%s> not found.", Args.Arg(2));
- break;
- case CMD_FUNO: // Find user number
- ASSERT(Args.m_argc == 3);
- if (!CUsr::FindUser(atoi(Args.Arg(2)), cBuf))
- SendMsg(550,"User #%s not found.", Args.Arg(2));
- else
- SendMsg(200,"%s", cBuf);
- break;
- case CMD_FUNA: // Find user name
- ASSERT(Args.m_argc == 4);
- if ((MyUser = CUsr::FindUser(atoi(Args.Arg(3)), Args.Arg(2))) == INVALID_USER_VALUE)
- SendMsg(550,"User %s not found.", Args.Arg(2));
- else
- SendMsg(200,"%d", MyUser);
- break;
- case CMD_STUS: // Set user
- if (Args.m_argc != 3)
- SendMsg(501,"Missing required parameter.");
- else if (CUsr::SetUserOption(UT_USER, Args.Arg(2)))
- SendMsg(200, "OK");
- else
- SendMsg(550,"Failed to set User option. (syntax: User/Option=new value)");
- break;
- case CMD_GUOP:
- ASSERT(Args.m_argc == 4);
- if (CUsr::GetUserOption(UT_USER, Args.Arg(3), cBuf))
- SendMsg(200, "%s", cBuf);
- else
- SendMsg(550,"Failed to get User option. (syntax: User/Option=default value)");
- break;
- case CMD_EVON: //
- if (m_Events->Register(atoi(Args.Arg(2))))
- SendMsg(200, "Events %d (0x%x) is enabled.",
- m_Events->m_EventTypes, m_Events->m_EventTypes);
- else
- SendMsg(550,"Failed to register one or more events");
- break;
- case CMD_EVOF:
- m_Events->Close(atoi(Args.Arg(2)));
- SendMsg(200, "Event(s) %d is closed", atoi(Args.Arg(2)));
- break;
- case CMD_STAT:
- CDaemonStatusSvr::GetStats(cBuf);
- SendMsg(200, cBuf);
- break;
- case CMD_VER:
- SendMsg(200, "%s %s%s %s",
- CProgramInfo::m_PROGRAM,
- CProgramInfo::m_VERSION,
- #ifdef _DEBUG
- "-DEBUG",
- #else
- "",
- #endif // DEBUG
- CProgramInfo::m_COPYRIGHT);
- break;
- case CMD_SHDN: // Shutdown
- SendMsg(200, "System is shutting down.");
- CDaemonNotificationWnd::GetWin()->PostMessage(WM_COMMAND, ID_MENU_STOPANDQUIT);
- break;
- case CMD_GONL: // Go online
- SendMsg(200, "OK");
- CDaemonNotificationWnd::GetWin()->PostMessage(WM_COMMAND, ID_MENU_GOONLINE);
- break;
- case CMD_GOOF: // Go offline
- SendMsg(200, "OK");
- CDaemonNotificationWnd::GetWin()->PostMessage(WM_COMMAND, ID_MENU_GOOFFLINE);
- break;
- case CMD_RSTR: // Restart
- SendMsg(200, "System is restarting down.");
- CDaemonNotificationWnd::GetWin()->PostMessage(WM_COMMAND, ID_MENU_RESTART);
- break;
- case CMD_LDIR: // List directory
- {
- /*
- CFileInfoList List;
- if (CFsys::GetFsys()->BldFileInfoList(m_User, "", List, "", Args.Arg(2), TRUE))
- {
- List.ListRaw(cBuf);
- SendMsg(200, "%s", cBuf);
- }
- else*/
- if (m_pFsys)
- m_pFsys->Logout();
- m_pFsys = new CRAFsys((LPVOID *)&m_pFsys);
- if (!m_pFsys->List(Args.Arg(2), this))
- {
- SendMsg(550, "Failed to list directory '%s'", Args.Arg(2));
- }
- }
- break;
- case CMD_CHMOD:
- {
- if (m_pFsys)
- m_pFsys->Logout();
- m_pFsys = new CRAFsys((LPVOID *)&m_pFsys);
- CCmdArgs MyArgs("chmod", Args[1], m_Parser);
- if (!m_pFsys->ChMod(MyArgs, this))
- {
- SendMsg(451, "chmod failed.");
- LogMsg(LOGF_WARNINGS,"chmod failed before callback");
- }
- }
- break;
- // Command errors
- case CMD_MISSING_PARAMETER:
- SendMsg(501,"Missing parameter in command %s", Text);
- break;
- case CMD_UNKNOWN_COMMAND:
- SendMsg(500, "%s: unrecognized command.", Text);
- break;
- case CMD_NOT_IMPLEMENTED:
- SendMsg(502, "%s: command not implemented.", Text);
- break;
- case CMD_BAD_LEVEL:
- SendMsg(530, "Please login with USER and PASS.");
- break;
- case CMD_PARSE_ERROR:
- case CMD_UNKNOWN_PARAMETER:
- SendMsg(500,"'%s': command not understood.", Text);
- break;
- default:
- SendMsg(502,"%s: Command not implemented.", Args.Arg(0));
- break;
- }
- prompt:
- if (!m_LocalEcho)
- break;
- SendCtrlMsg(230,"Command: ", FALSE, FALSE);
- break;
- default:
- SendCtrlMsg(451,"Server error. Unhandled value in m_State.nCommand: ", FALSE, FALSE);
- }
- if ((m_LocalEcho == '*') && (m_State != GOTNAME))
- m_LocalEcho = 1;
- return Rval;;
- }
- void CDaemonMaintananceSocket::Virgin()
- {
- CTextSock::Virgin();
- }
- BOOL CDaemonMaintananceSocket::ProcessTelnetNegotiation(int ch1, int ch2)
- {
- return CTextSock::ProcessTelnetNegotiation(ch1, ch2);
- }
- void CDaemonMaintananceSocket::InsertPendingText()
- {
- CTextSock::InsertPendingText();
- }
- BOOL CDaemonMaintananceSocket::ExpandMacro(LPSTR *To, LPCSTR MacroName, int AvailBytes)
- {
- if (CTextSock::ExpandMacro(To, MacroName, AvailBytes))
- return TRUE;
- // TODO: Add expansion here and return TRUE if the macro was expanded
- return FALSE;
- }
- void CDaemonMaintananceSocket::OnConnect( int nErrorCode )
- {
- try
- {
- _OnConnect(nErrorCode);
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CDaemonMaintananceSocket::OnConnect(%d) - Caught exception '%s' from module %s",
- nErrorCode, pExc->m_ErrorText, pExc->m_ErrorText);
- if (!OnHandleWinsockErr(pExc->m_ErrorNum))
- delete this;
- delete pExc;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CDaemonMaintananceSocket::OnConnect(%d) - Caught unknown exception", nErrorCode);
- }
- }
- void CDaemonMaintananceSocket::_OnConnect( int nErrorCode )
- {
- CTextSock::OnConnect(nErrorCode);
- }
- void CDaemonMaintananceSocket::OnClose( int nErrorCode )
- {
- try
- {
- CTextSock::OnClose(nErrorCode);
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CDaemonMaintananceSocket::OnClose(%d) - Caught exception '%s' from module %s",
- nErrorCode, pExc->m_ErrorText, pExc->m_ErrorText);
- if (!OnHandleWinsockErr(pExc->m_ErrorNum))
- delete this;
- delete pExc;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CDaemonMaintananceSocket::OnClose(%d) - Caught unknown exception", nErrorCode);
- }
- }
- void CDaemonMaintananceSocket::OnSend( int nErrorCode )
- {
- try
- {
- CTextSock::OnSend(nErrorCode);
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CDaemonMaintananceSocket::OnSend(%d) - Caught exception '%s' from module %s",
- nErrorCode, pExc->m_ErrorText, pExc->m_ErrorText);
- if (!OnHandleWinsockErr(pExc->m_ErrorNum))
- delete this;
- delete pExc;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CDaemonMaintananceSocket::OnSend(%d) - Caught unknown exception", nErrorCode);
- }
- }
- void CDaemonMaintananceSocket::OnOutOfBandData( int nErrorCode )
- {
- try
- {
- CTextSock::OnOutOfBandData(nErrorCode);
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CDaemonMaintananceSocket::OnOutOfBandData(%d) - Caught exception '%s' from module %s",
- nErrorCode, pExc->m_ErrorText, pExc->m_ErrorText);
- if (!OnHandleWinsockErr(pExc->m_ErrorNum))
- delete this;
- delete pExc;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CDaemonMaintananceSocket::OnOutOfBandData(%d) - Caught unknown exception", nErrorCode);
- }
- }
- void CDaemonMaintananceSocket::OnReceive( int nErrorCode )
- {
- try
- {
- CTextSock::OnReceive(nErrorCode);
- }
- catch(CSocketException *pExc)
- {
- LogMsg(LOGF_DEBUG,"CDaemonMaintananceSocket::OnReceive(%d) - Caught exception '%s' from module %s",
- nErrorCode, pExc->m_ErrorText, pExc->m_ErrorText);
- if (!OnHandleWinsockErr(pExc->m_ErrorNum))
- delete this;
- delete pExc;
- }
- catch(...)
- {
- CLog::GetLog()->LogMsg(LOGF_ERROR,"CDaemonMaintananceSocket::OnReceive(%d) - Caught unknown exception", nErrorCode);
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // CRAFsys
- CRAFsys::CRAFsys(LPVOID *pRef)
- :CUserFsys(pRef)
- {
- m_NextStep = 0;
- m_AsyncSelectMaskSaved = 0;
- m_StateSaved = 0;
- m_pSock = NULL;
- }
- BOOL CRAFsys::SetOnHold()
- {
- m_AsyncSelectMaskSaved = m_pSock->m_AsyncSelectMask;
- m_StateSaved = m_pSock->m_State;
- // Prevent socket read/write events
- m_pSock->m_AsyncSelectMask &= ~(FD_READ);
- m_pSock->AsyncSelect(m_pSock->m_AsyncSelectMask);
- // Set block state
- m_pSock->m_State = HOLD;
- return TRUE;
- }
- void CRAFsys::ReleaseHold()
- {
- m_pSock->m_State = m_StateSaved;
- m_pSock->m_AsyncSelectMask = m_AsyncSelectMaskSaved;
- m_pSock->AsyncSelect(m_pSock->m_AsyncSelectMask);
- }
- void CRAFsys::CheckForZombie()
- {
- CUserFsys::CheckForZombie();
- }
- BOOL CRAFsys::Create(CDaemonMaintananceSocket *pSock)
- {
- m_pSock = pSock;
- m_IsAdmin = CUsr::IsAdmin(m_pSock->m_User);
- USER Class = CUsr::GetUserClass(m_pSock->m_User);
- return CUserFsys::Create("/", "/", m_pSock->m_User, Class, pSock->m_SocketName);
- }
- // Called after the file system is initialized
- // for the user
- BOOL CRAFsys::OnCreate(int nErrorCode)
- {
- CUserFsys::OnCreate(nErrorCode);
- if (nErrorCode)
- {
- m_pSock->SendMsg(421, "Internal error - unable to initialize your file system");
- m_pSock->LogMsg(LOGF_ERROR,"Unable to initialize the users file system.");
- delete this;
- return FALSE;
- }
- return NextStep();
- }
- BOOL CRAFsys::NextStep()
- {
- switch(m_NextStep)
- {
- case DOLIST:
- if (!DoList())
- {
- m_pSock->SendMsg(421, "Internal error - unable to proceed with list");
- m_pSock->LogMsg(LOGF_ERROR,"Unable to initialize the users file system.");
- delete this;
- return FALSE;
- }
- break;
- case DOCHMOD:
- if (!DoChmod())
- {
- m_pSock->SendMsg(421, "Internal error - unable to proceed with list");
- m_pSock->LogMsg(LOGF_ERROR,"Unable to initialize the users file system.");
- delete this;
- return FALSE;
- }
- break;
- default:
- m_pSock->SendMsg(421, "Internal error - Invalid next step %d", m_NextStep);
- m_pSock->LogMsg(LOGF_ERROR,"Internal error - Invalid next step %d", m_NextStep);
- delete this;
- return FALSE;
- }
- return TRUE;
- }
- BOOL CRAFsys::List(LPCSTR Path, CDaemonMaintananceSocket *pSock)
- {
- m_Path = Path;
- // Create the file system
- m_NextStep = DOLIST;
- return Create(pSock);
- }
- BOOL CRAFsys::DoList()
- {
- m_NextStep = 0;
- m_FsysPath1 = m_Path;
- return ProcessRequest(FSM_WLST, (WPARAM)this, 0);
- }
- BOOL CRAFsys::OnWlist(int nErrorCode)
- {
- // List raw.
- if (nErrorCode)
- m_pSock->SendMsg(550, "WLIST failed with error code %d", nErrorCode);
- else
- m_pSock->SendMsg(200, "%s", m_FsysPath2);
- Logout();
- return TRUE;
- }
- BOOL CRAFsys::ChMod(CCmdArgs& Args, CDaemonMaintananceSocket *pSock)
- {
- m_CmdArgStore = Args;
- // Create the file system
- m_NextStep = DOCHMOD;
- return Create(pSock);
- }
- BOOL CRAFsys::DoChmod()
- {
- m_NextStep = 0;
- m_FsysPath1 = m_Path;
- return CUserFsys::ChMod(m_CmdArgStore);
- }
- BOOL CRAFsys::OnChmod(int nErrorCode)
- {
- if (nErrorCode && m_Output.IsEmpty())
- {
- m_pSock->SendMsg(551, "chmod failed.");
- m_pSock->LogMsg(LOGF_WARNINGS,"chmod failed after callback, error %d", nErrorCode);
- }
- else
- {
- m_pSock->SuspendMacros();
- m_pSock->SendMsg(200, "chmod: %s", m_Output);
- m_pSock->EnableMacros();
- }
- Logout();
- return TRUE;
- }