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.

168 lines
4.9 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. GUID ServiceClassId = { /* 5b50962a-e5a5-11cf-a555-00c04fd8d4ac */
  13. 0x5b50962a,
  14. 0xe5a5,
  15. 0x11cf,
  16. {0xa5, 0x55, 0x00, 0xc0, 0x4f, 0xd8, 0xd4, 0xac}
  17. };
  18. GUID ServiceGuid = { 0x47da8500, 0x96a1, 0x11cd, 0x90, 0x1d,
  19. 0x20, 0x4c, 0x4f, 0x4f, 0x50, 0x20 };
  20. #define BUFFSIZE 3000
  21. _cdecl
  22. main(int argc, char **argv)
  23. {
  24. HANDLE hLib;
  25. WCHAR Buffer[BUFFSIZE];
  26. PWSAQUERYSETW Query = (PWSAQUERYSETW)Buffer;
  27. HANDLE hRnr;
  28. DWORD dwIp;
  29. DWORD dwQuerySize = BUFFSIZE;
  30. WSADATA wsaData;
  31. ANSI_STRING asServiceInstanceName;
  32. UNICODE_STRING usServiceInstanceName;
  33. WCHAR UnicodeStringBuf[1024];
  34. ANSI_STRING asContext;
  35. UNICODE_STRING usContext;
  36. WCHAR UnicodeStringBuf2[1024];
  37. AFPROTOCOLS lpAfpProtocols[3];
  38. usServiceInstanceName.Length = 0;
  39. usServiceInstanceName.MaximumLength = 1024;
  40. usServiceInstanceName.Buffer = UnicodeStringBuf;
  41. usContext.Length = 0;
  42. usContext.MaximumLength = 1024;
  43. usContext.Buffer = UnicodeStringBuf2;
  44. if ( argc != 5 )
  45. {
  46. printf( "\nUsage: lookup <Name> <Context> Deep Echo\n" );
  47. return( -1 );
  48. }
  49. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  50. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  51. &asServiceInstanceName,
  52. FALSE );
  53. RtlInitAnsiString( &asContext, argv[2] );
  54. RtlAnsiStringToUnicodeString( &usContext,
  55. &asContext,
  56. FALSE );
  57. WSAStartup(MAKEWORD(1, 1), &wsaData);
  58. memset(Query, 0, sizeof(*Query));
  59. Query->dwSize = sizeof(*Query);
  60. if ( usServiceInstanceName.Buffer[0] != L'*' )
  61. {
  62. Query->lpszServiceInstanceName = usServiceInstanceName.Buffer;
  63. }
  64. if ( argv[4][0] == 'E' )
  65. {
  66. Query->lpServiceClassId = &ServiceGuid;
  67. }
  68. else
  69. {
  70. Query->lpServiceClassId = &ServiceClassId;
  71. }
  72. Query->lpVersion = 0;
  73. Query->dwNameSpace = NS_NTDS;
  74. Query->lpNSProviderId = 0;
  75. Query->lpszContext = usContext.Buffer;
  76. Query->dwNumberOfProtocols = 0;
  77. lpAfpProtocols[0].iAddressFamily = AF_INET;
  78. lpAfpProtocols[0].iProtocol = PF_INET;
  79. lpAfpProtocols[1].iAddressFamily = AF_IPX;
  80. lpAfpProtocols[1].iProtocol = PF_IPX;
  81. lpAfpProtocols[2].iAddressFamily = AF_UNSPEC;
  82. lpAfpProtocols[2].iProtocol = PF_UNSPEC;
  83. Query->lpafpProtocols = lpAfpProtocols;
  84. if( WSALookupServiceBegin( Query,
  85. ( argv[3][0] == 'D' ? LUP_DEEP : 0 ) |
  86. LUP_RETURN_NAME |
  87. LUP_RETURN_TYPE |
  88. LUP_RETURN_VERSION |
  89. LUP_RETURN_COMMENT |
  90. LUP_RETURN_ADDR |
  91. LUP_RETURN_BLOB,
  92. // LUP_RETURN_ALIASES |
  93. // LUP_RETURN_QUERY_STRING |
  94. // LUP_RETURN_ALL,
  95. &hRnr ) == SOCKET_ERROR )
  96. {
  97. printf( "LookupBegin failed %d\n", GetLastError() );
  98. }
  99. while ( WSALookupServiceNext( hRnr,
  100. 0,
  101. &dwQuerySize,
  102. Query ) == NO_ERROR )
  103. {
  104. printf( "Next got: \n" );
  105. printf( " dwSize = %d\n",
  106. Query->dwSize );
  107. printf( " dwOutputFlags = %d\n",
  108. Query->dwOutputFlags );
  109. printf( " lpszServiceInstanceName = %ws\n",
  110. Query->lpszServiceInstanceName );
  111. if ( Query->lpVersion )
  112. {
  113. printf( " lpVersion->dwVersion = %d\n",
  114. Query->lpVersion->dwVersion );
  115. printf( " lpVersion->ecHow = %d\n",
  116. Query->lpVersion->ecHow );
  117. }
  118. if ( Query->lpszComment )
  119. {
  120. printf( " lpszComment = %ws\n",
  121. Query->lpszComment );
  122. }
  123. printf( " dwNameSpace = %d\n",
  124. Query->dwNameSpace );
  125. if ( Query->lpszContext )
  126. {
  127. printf( " lpszContext = %ws\n",
  128. Query->lpszContext );
  129. }
  130. printf( " dwNumberOfCsAddrs = %d\n",
  131. Query->dwNumberOfCsAddrs );
  132. }
  133. printf( "Next finished with %d\n", GetLastError() );
  134. if( WSALookupServiceEnd( hRnr ) )
  135. {
  136. printf( "ServiceEnd failed %d\n", GetLastError() );
  137. }
  138. WSACleanup();
  139. return(0);
  140. }