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.

194 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. Domain.c
  5. Abstract:
  6. This file contains routines to implement remote versions of the LanMan
  7. domain APIs on downlevel servers. The APIs are RxNetGetDCName and
  8. RxNetLogonEnum.
  9. Author:
  10. John Rogers (JohnRo) 18-Jul-1991
  11. Environment:
  12. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  13. Requires ANSI C extensions: slash-slash comments, long external names.
  14. Revision History:
  15. 18-Jul-1991 JohnRo
  16. Implement downlevel NetGetDCName.
  17. 27-Jul-1991 JohnRo
  18. Made changes suggested by PC-LINT.
  19. 07-Feb-1992 JohnRo
  20. Use NetApiBufferAllocate() instead of private version.
  21. 01-Sep-1992 JohnRo
  22. RAID 5088: NetGetDCName to downlevel doesn't UNICODE translate.
  23. Minor debug output fix.
  24. Changed to use _PREFIX equates.
  25. --*/
  26. // These must be included first:
  27. #include <windef.h> // IN, LPTSTR, DWORD, TCHAR, etc.
  28. #include <lmcons.h> // NET_API_STATUS, UNCLEN.
  29. // These may be included in any order:
  30. #include <apinums.h> // API_ equates.
  31. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  32. #include <lmerr.h> // NERR_ and ERROR_ equates.
  33. #include <lmwksta.h> // NetWkstaGetInfo(), LPWKSTA_INFO_100.
  34. #include <netdebug.h> // NetpAssert().
  35. #include <prefix.h> // PREFIX_ equates.
  36. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  37. #include <rx.h> // RxRemoteApi().
  38. #include <rxpdebug.h> // IF_DEBUG().
  39. #include <rxdomain.h> // My prototypes.
  40. #define MAX_DCNAME_BYTE_COUNT ( MAX_PATH * sizeof(TCHAR) )
  41. NET_API_STATUS
  42. RxNetGetDCName (
  43. IN LPTSTR UncServerName,
  44. IN LPTSTR OptionalDomain OPTIONAL,
  45. OUT LPBYTE *BufPtr
  46. )
  47. /*++
  48. Routine Description:
  49. RxNetGetDCName performs the same function as NetGetDCName, except that the
  50. server name is known to refer to a downlevel server.
  51. Arguments:
  52. UncServerName - Same as NetGetDCName, except UncServerName must not be
  53. null, and must not refer to the local computer.
  54. OptionalDomain - Same as NetGetDCName.
  55. BufPtr - Same as NetGetDCName.
  56. Return Value:
  57. NET_API_STATUS - Same as NetGetDCName.
  58. --*/
  59. {
  60. LPTSTR DCName = NULL;
  61. LPTSTR Domain; // filled-in with domain name (not left NULL).
  62. NET_API_STATUS Status;
  63. LPWKSTA_INFO_100 WkstaInfo = NULL;
  64. // Assume something might go wrong, and make error paths easier to
  65. // code. Also, check for a bad pointer before we do anything.
  66. *BufPtr = NULL;
  67. //
  68. // Get actual domain name.
  69. //
  70. if ( (OptionalDomain != NULL) && (*OptionalDomain != '\0') ) {
  71. Domain = OptionalDomain;
  72. } else {
  73. // Do NetWkstaGetInfo to get primary domain.
  74. Status = NetWkstaGetInfo (
  75. NULL, // no server name (want LOCAL idea of primary domain)
  76. 100, // level
  77. (LPBYTE *) (LPVOID *) & WkstaInfo // output buffer (allocated)
  78. );
  79. if (Status != NERR_Success) {
  80. IF_DEBUG(DOMAIN) {
  81. NetpKdPrint(( PREFIX_NETAPI
  82. "RxNetGetDCName: wksta get info failed, stat="
  83. FORMAT_API_STATUS ".\n", Status));
  84. }
  85. goto Done;
  86. }
  87. NetpAssert( WkstaInfo->wki100_langroup != NULL );
  88. IF_DEBUG(DOMAIN) {
  89. NetpKdPrint(( PREFIX_NETAPI
  90. "RxNetGetDCName: wksta says domain is:\n" ));
  91. NetpDbgHexDump( (LPVOID) WkstaInfo->wki100_langroup, UNLEN+1 );
  92. }
  93. Domain = WkstaInfo->wki100_langroup;
  94. }
  95. NetpAssert( Domain != NULL );
  96. NetpAssert( *Domain != '\0' );
  97. //
  98. // Allocate memory for DCName.
  99. //
  100. Status = NetApiBufferAllocate (
  101. MAX_DCNAME_BYTE_COUNT,
  102. (LPVOID *) & DCName
  103. );
  104. if (Status != NERR_Success) {
  105. goto Done;
  106. }
  107. //
  108. // Actually remote the API to the downlevel server, to get DCName.
  109. //
  110. Status = RxRemoteApi(
  111. API_WGetDCName, // API number
  112. UncServerName,
  113. REMSmb_NetGetDCName_P, // parm desc
  114. REM16_dc_name, // data desc 16
  115. REM32_dc_name, // data desc 32
  116. REMSmb_dc_name, // data desc SMB
  117. NULL, // no aux desc 16
  118. NULL, // no aux desc 32
  119. NULL, // no aux desc SMB
  120. FALSE, // not a null session API
  121. // rest of API's arguments, in LM 2.x 32-bit format:
  122. Domain, // domain name (filled-in already)
  123. DCName, // response
  124. MAX_DCNAME_BYTE_COUNT // size of response buffer
  125. );
  126. // It's safe to free WkstaInfo now (we've been using it with Domain until
  127. // now.)
  128. Done:
  129. //
  130. // Tell caller how things went. Clean up as necessary.
  131. //
  132. if (Status == NERR_Success) {
  133. *BufPtr = (LPBYTE) DCName;
  134. } else {
  135. if (DCName != NULL) {
  136. (void) NetApiBufferFree ( DCName );
  137. }
  138. }
  139. if (WkstaInfo != NULL) {
  140. // Free memory which NetWkstaGetInfo allocated for us.
  141. (void) NetApiBufferFree ( WkstaInfo );
  142. }
  143. return (Status);
  144. } // RxNetGetDCName