Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.2 KiB

  1. #define DBG 1
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <memory.h>
  8. #include <malloc.h>
  9. #include <stdlib.h>
  10. #ifndef WIN32_LEAN_AND_MEAN
  11. #define WIN32_LEAN_AND_MEAN
  12. #endif
  13. #include <windows.h>
  14. #include <rpc.h>
  15. #include <midles.h>
  16. #include "..\smgr.h"
  17. #define RPC_CHAR WCHAR
  18. #define CHECK_STATUS(status, string) if (status) { \
  19. printf("%s failed - %d (%08x)\n", (string), (status), (status)); \
  20. exit(1); \
  21. } else printf("%s okay\n", (string));
  22. PVOID SystemHeap = NULL;
  23. extern "C" {
  24. void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t bytes)
  25. {
  26. return RtlAllocateHeap(SystemHeap, 0, bytes);
  27. }
  28. void __RPC_USER MIDL_user_free(void __RPC_FAR * p)
  29. {
  30. RtlFreeHeap(SystemHeap, 0, p);
  31. }
  32. }
  33. int __cdecl main(int argc, char *argv[])
  34. {
  35. RPC_STATUS status;
  36. unsigned char __RPC_FAR *stringBinding;
  37. handle_t binding;
  38. SyncManagerCommands CurrentCommand;
  39. UString *param = NULL;
  40. int ClientOrServer;
  41. BOOL bResult;
  42. STARTUPINFO startInfo;
  43. PROCESS_INFORMATION processInfo;
  44. RPC_CHAR CmdLine[400];
  45. memset(&startInfo, 0, sizeof(startInfo));
  46. startInfo.cb = sizeof(startInfo);
  47. SystemHeap = GetProcessHeap();
  48. if (argc != 3)
  49. {
  50. printf("Usage:\n\tsyncclnt s|c syncmgr_server\n");
  51. return 2;
  52. }
  53. if (*argv[1] == 'c' || *argv[1] == 'C')
  54. ClientOrServer = 1;
  55. else
  56. ClientOrServer = 0;
  57. status = RpcStringBindingComposeA(0,
  58. (unsigned char *)"ncacn_ip_tcp",
  59. (unsigned char *)argv[2],
  60. (unsigned char *)"",
  61. 0,
  62. &stringBinding);
  63. CHECK_STATUS(status, "RpcStringBindingCompose");
  64. status = RpcBindingFromStringBindingA(stringBinding, &binding);
  65. CHECK_STATUS(status, "RpcBindingFromStringBinding");
  66. RpcStringFreeA(&stringBinding);
  67. DeleteFile(L"c:\\perf.log");
  68. RpcMgmtSetComTimeout(binding, RPC_C_BINDING_INFINITE_TIMEOUT);
  69. // start the loop
  70. do
  71. {
  72. GetCommand(binding, ClientOrServer, &CurrentCommand, &param);
  73. switch (CurrentCommand)
  74. {
  75. case smcNOP:
  76. continue;
  77. case smcExec:
  78. wcscpy(CmdLine, param->pString);
  79. CmdLine[param->nlength] = 0;
  80. MIDL_user_free(param);
  81. param = NULL;
  82. bResult = CreateProcess(NULL, CmdLine, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL,
  83. NULL, &startInfo, &processInfo);
  84. if (bResult)
  85. {
  86. CloseHandle(processInfo.hThread);
  87. WaitForSingleObject(processInfo.hProcess, INFINITE);
  88. CloseHandle(processInfo.hProcess);
  89. }
  90. else
  91. {
  92. printf("CreateProcess failed: %S, %d\n", CmdLine, GetLastError());
  93. return 2;
  94. }
  95. break;
  96. }
  97. }
  98. while(CurrentCommand != smcExit);
  99. return 0;
  100. }