Leaked source code of windows server 2003
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.

140 lines
4.3 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winsock2.h>
  6. #include <wsipx.h>
  7. #include <svcguid.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <rpc.h>
  11. #include <rpcdce.h>
  12. #define BUFFSIZE 3000
  13. GUID ServiceClassId = { /* 5b50962a-e5a5-11cf-a555-00c04fd8d4ac */
  14. 0x5b50962a,
  15. 0xe5a5,
  16. 0x11cf,
  17. {0xa5, 0x55, 0x00, 0xc0, 0x4f, 0xd8, 0xd4, 0xac}
  18. };
  19. _cdecl
  20. main(int argc, char **argv)
  21. {
  22. HANDLE hLib;
  23. WCHAR Buffer[BUFFSIZE];
  24. PWSAQUERYSETW Query = (PWSAQUERYSETW)Buffer;
  25. HANDLE hRnr;
  26. DWORD dwIp;
  27. DWORD dwQuerySize = BUFFSIZE;
  28. WSADATA wsaData;
  29. ANSI_STRING asServiceInstanceName;
  30. UNICODE_STRING usServiceInstanceName;
  31. WCHAR UnicodeStringBuf[1024];
  32. ANSI_STRING asContext;
  33. UNICODE_STRING usContext;
  34. WCHAR UnicodeStringBuf2[1024];
  35. usServiceInstanceName.Length = 0;
  36. usServiceInstanceName.MaximumLength = 1024;
  37. usServiceInstanceName.Buffer = UnicodeStringBuf;
  38. usContext.Length = 0;
  39. usContext.MaximumLength = 1024;
  40. usContext.Buffer = UnicodeStringBuf2;
  41. if ( argc < 2 || argc > 4 )
  42. {
  43. printf( "\nUsage: lookup <Name> <Context> Deep\n" );
  44. return( -1 );
  45. }
  46. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  47. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  48. &asServiceInstanceName,
  49. FALSE );
  50. RtlInitAnsiString( &asContext, argv[2] );
  51. RtlAnsiStringToUnicodeString( &usContext,
  52. &asContext,
  53. FALSE );
  54. WSAStartup(MAKEWORD(1, 1), &wsaData);
  55. memset(Query, 0, sizeof(*Query));
  56. Query->dwSize = sizeof(*Query);
  57. Query->lpszServiceInstanceName = usServiceInstanceName.Buffer;
  58. Query->lpVersion = 0;
  59. Query->dwNameSpace = NS_NTDS;
  60. Query->lpNSProviderId = 0;
  61. Query->lpszContext = usContext.Buffer;
  62. Query->dwNumberOfProtocols = 0;
  63. Query->lpServiceClassId = &ServiceClassId;
  64. if( WSALookupServiceBegin( Query,
  65. ( argv[3][0] == 'D' ? LUP_DEEP : 0 ) |
  66. LUP_RETURN_NAME |
  67. // LUP_RETURN_TYPE |
  68. // LUP_RETURN_VERSION |
  69. LUP_RETURN_COMMENT |
  70. // LUP_RETURN_ADDR |
  71. // LUP_RETURN_BLOB |
  72. // LUP_RETURN_ALIASES |
  73. // LUP_RETURN_QUERY_STRING |
  74. LUP_CONTAINERS,
  75. // LUP_RETURN_ALL,
  76. &hRnr ) == SOCKET_ERROR )
  77. {
  78. printf( "LookupBegin failed %d\n", GetLastError() );
  79. }
  80. while ( WSALookupServiceNext( hRnr,
  81. 0,
  82. &dwQuerySize,
  83. Query ) == NO_ERROR )
  84. {
  85. printf( "Next got: \n" );
  86. printf( " dwSize = %d\n",
  87. Query->dwSize );
  88. printf( " dwOutputFlags = %d\n",
  89. Query->dwOutputFlags );
  90. printf( " lpszServiceInstanceName = %ws\n",
  91. Query->lpszServiceInstanceName );
  92. if ( Query->lpVersion )
  93. {
  94. printf( " lpVersion->dwVersion = %d\n",
  95. Query->lpVersion->dwVersion );
  96. printf( " lpVersion->ecHow = %d\n",
  97. Query->lpVersion->ecHow );
  98. }
  99. if ( Query->lpszComment )
  100. {
  101. printf( " lpszComment = %ws\n",
  102. Query->lpszComment );
  103. }
  104. printf( " dwNameSpace = %d\n",
  105. Query->dwNameSpace );
  106. if ( Query->lpszContext )
  107. {
  108. printf( " lpszContext = %ws\n",
  109. Query->lpszContext );
  110. }
  111. printf( " dwNumberOfCsAddrs = %d\n",
  112. Query->dwNumberOfCsAddrs );
  113. }
  114. printf( "Next finished with %d\n", GetLastError() );
  115. if( WSALookupServiceEnd( hRnr ) )
  116. {
  117. printf( "ServiceEnd failed %d\n", GetLastError() );
  118. }
  119. WSACleanup();
  120. return(0);
  121. }