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.

164 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. rndilslk.cpp
  5. Abstract:
  6. This module contains code to look up ILS in NTDS.
  7. --*/
  8. #include "stdafx.h"
  9. #include <initguid.h>
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // //
  12. // Global constants //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // {C9F17940-79A7-11d1-B008-00C04FC31FEE}
  16. DEFINE_GUID(CLSID_ILSServicClass,
  17. 0xc9f17940, 0x79a7, 0x11d1, 0xb0, 0x8, 0x0, 0xc0, 0x4f, 0xc3, 0x1f, 0xee);
  18. #define BUFFSIZE 3000
  19. int LookupILSServiceBegin(
  20. HANDLE * pHandle
  21. )
  22. /*++
  23. Routine Description:
  24. Begin ILS service enumeration.
  25. Arguments:
  26. pHandle - the handle of the enumerator.
  27. Return Value:
  28. Wisock error codes.
  29. --*/
  30. {
  31. WSAVERSION Version;
  32. AFPROTOCOLS lpAfpProtocols[1];
  33. WSAQUERYSET Query;
  34. if (IsBadWritePtr(pHandle, sizeof(HANDLE *)))
  35. {
  36. return ERROR_INVALID_PARAMETER;
  37. }
  38. ZeroMemory(&Query, sizeof(WSAQUERYSET));
  39. Query.dwNumberOfProtocols = 1;
  40. lpAfpProtocols[0].iAddressFamily = AF_INET;
  41. lpAfpProtocols[0].iProtocol = PF_INET;
  42. Query.lpafpProtocols = lpAfpProtocols;
  43. Query.lpszServiceInstanceName = L"*";
  44. Query.dwNameSpace = NS_NTDS;
  45. Query.dwSize = sizeof(Query);
  46. Query.lpServiceClassId = (GUID *)&CLSID_ILSServicClass;
  47. if (WSALookupServiceBegin(
  48. &Query,
  49. LUP_RETURN_ALL,
  50. pHandle ) == SOCKET_ERROR )
  51. {
  52. return WSAGetLastError();
  53. }
  54. return NOERROR;
  55. }
  56. int LookupILSServiceNext(
  57. HANDLE Handle,
  58. TCHAR * pBuf,
  59. DWORD * pdwBufSize,
  60. WORD * pwPort
  61. )
  62. /*++
  63. Routine Description:
  64. look up the next ILS server.
  65. Arguments:
  66. Handle - The handle of the enumeration.
  67. pBuf - A pointer to a buffer of TCHARs that will store the DNS
  68. name of the ILS server.
  69. pdwBufSize - The size of the buffer.
  70. pwPort - The port that the ILS server is using.
  71. Return Value:
  72. Wisock error codes.
  73. --*/
  74. {
  75. TCHAR buffer[BUFFSIZE];
  76. DWORD dwSize = BUFFSIZE;
  77. LPWSAQUERYSET lpResult = (LPWSAQUERYSET)buffer;
  78. LPCSADDR_INFO lpCSAddrInfo;
  79. LPSOCKADDR lpSocketAddress;
  80. if (WSALookupServiceNext(Handle, 0, &dwSize, lpResult) == SOCKET_ERROR)
  81. {
  82. return WSAGetLastError();
  83. }
  84. lpCSAddrInfo = lpResult->lpcsaBuffer;
  85. if (IsBadReadPtr(lpCSAddrInfo, sizeof(CSADDR_INFO)))
  86. {
  87. return ERROR_BAD_FORMAT;
  88. }
  89. lpSocketAddress = lpCSAddrInfo->RemoteAddr.lpSockaddr;
  90. if (IsBadReadPtr(lpSocketAddress, sizeof(SOCKADDR)))
  91. {
  92. return ERROR_BAD_FORMAT;
  93. }
  94. *pwPort = ((struct sockaddr_in*) lpSocketAddress->sa_data)->sin_port;
  95. lstrcpyn(pBuf, lpResult->lpszServiceInstanceName, *pdwBufSize);
  96. *pdwBufSize = lstrlen(pBuf);
  97. return NOERROR;
  98. }
  99. int LookupILSServiceEnd(
  100. HANDLE Handle
  101. )
  102. /*++
  103. Routine Description:
  104. Finish the ils service enumerator.
  105. Arguments:
  106. Handle - the handle of the enumerator.
  107. Return Value:
  108. Wisock error codes.
  109. --*/
  110. {
  111. if (WSALookupServiceEnd(Handle) == SOCKET_ERROR)
  112. {
  113. return WSAGetLastError();
  114. }
  115. return NOERROR;
  116. }