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.

251 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. WksUser.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetWkstaUserEnum API.
  7. Author:
  8. John Rogers (JohnRo) 19-Nov-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 19-Nov-1991 JohnRo
  14. Implement remote NetWkstaUserEnum().
  15. 21-Nov-1991 JohnRo
  16. Removed NT dependencies to reduce recompiles.
  17. 07-Feb-1992 JohnRo
  18. Use NetApiBufferAllocate() instead of private version.
  19. 14-Oct-1992 JohnRo
  20. RAID 9732: NetWkstaUserEnum to downlevel: wrong EntriesRead, Total?
  21. Set wkui1_oth_domains field.
  22. Use PREFIX_ equates.
  23. 03-Nov-1992 JohnRo
  24. RAID 10418: Fixed overactive assert when Status != NO_ERROR.
  25. Fixed memory leak if we couldn't allocate new buffer (old one got lost).
  26. Fixed memory leak if nobody is logged-on to target server.
  27. --*/
  28. // These must be included first:
  29. #include <windef.h> // IN, DWORD, etc.
  30. #include <lmcons.h> // LM20_ equates, NET_API_STATUS, etc.
  31. // These may be included in any order:
  32. #include <dlwksta.h> // WKSTA_INFO_0, MAX_WKSTA_ equates, etc.
  33. #include <lmapibuf.h> // NetApiBufferAllocate().
  34. #include <lmerr.h> // ERROR_ and NERR_ equates.
  35. #include <netdebug.h> // DBGSTATIC, NetpKdPrint(()), FORMAT_ equates.
  36. #include <netlib.h> // NetpCopyStringToBuffer().
  37. #include <prefix.h> // PREFIX_ equates.
  38. #include <rxpdebug.h> // IF_DEBUG().
  39. #include <rxwksta.h> // My prototypes, RxpGetWkstaInfoLevelEquivalent
  40. #include <tstring.h> // STRLEN().
  41. NET_API_STATUS
  42. RxNetWkstaUserEnum (
  43. IN LPTSTR UncServerName,
  44. IN DWORD Level,
  45. OUT LPBYTE *BufPtr,
  46. IN DWORD PrefMaxSize,
  47. OUT LPDWORD EntriesRead,
  48. OUT LPDWORD TotalEntries,
  49. IN OUT LPDWORD ResumeHandle OPTIONAL
  50. )
  51. /*++
  52. Routine Description:
  53. RxNetWkstaUserEnum performs the same function as NetWkstaUserEnum, except
  54. that the server name is known to refer to a downlevel server.
  55. Arguments:
  56. (Same as NetWkstaUserEnum, except UncServerName must not be null, and
  57. must not refer to the local computer.)
  58. Return Value:
  59. (Same as NetWkstaUserEnum.)
  60. --*/
  61. {
  62. LPBYTE NewInfo = NULL; // Buffer to be returned to caller.
  63. DWORD NewFixedSize;
  64. DWORD NewStringSize;
  65. LPWKSTA_INFO_1 OldInfo = NULL;
  66. const DWORD OldLevel = 1;
  67. NET_API_STATUS Status;
  68. UNREFERENCED_PARAMETER(PrefMaxSize);
  69. UNREFERENCED_PARAMETER(ResumeHandle);
  70. IF_DEBUG(WKSTA) {
  71. NetpKdPrint(( PREFIX_NETAPI
  72. "RxNetWkstaUserEnum: starting, server=" FORMAT_LPTSTR
  73. ", lvl=" FORMAT_DWORD ".\n", UncServerName, Level));
  74. }
  75. //
  76. // Error check DLL stub and the app.
  77. //
  78. NetpAssert(UncServerName != NULL);
  79. if (BufPtr == NULL) {
  80. Status = ERROR_INVALID_PARAMETER;
  81. goto Cleanup;
  82. }
  83. *BufPtr = NULL; // assume error; it makes error handlers easy to code.
  84. // This also forces possible GP fault before we allocate memory.
  85. //
  86. // Compute size of wksta user structure (including strings)
  87. //
  88. switch (Level) {
  89. case 0 :
  90. NewFixedSize = sizeof(WKSTA_USER_INFO_0);
  91. NewStringSize = (LM20_UNLEN+1) * sizeof(TCHAR);
  92. break;
  93. case 1 :
  94. NewFixedSize = sizeof(WKSTA_USER_INFO_1);
  95. NewStringSize =
  96. (LM20_UNLEN+1 + LM20_DNLEN+1 + MAX_PATH+1) * sizeof(TCHAR);
  97. break;
  98. default:
  99. Status = ERROR_INVALID_LEVEL;
  100. goto Cleanup;
  101. }
  102. //
  103. // Actually remote the API, which will get back the (old) info level
  104. // data in native format.
  105. //
  106. Status = RxpWkstaGetOldInfo(
  107. UncServerName, // Required, with \\name.
  108. OldLevel,
  109. (LPBYTE *) & OldInfo); // buffer (alloc and set this ptr)
  110. NetpAssert( Status != ERROR_MORE_DATA );
  111. NetpAssert( Status != NERR_BufTooSmall );
  112. if (Status == NERR_Success) {
  113. NetpAssert( OldInfo != NULL );
  114. if ( (OldInfo->wki1_username == NULL)
  115. || ( (*(OldInfo->wki1_username)) == (TCHAR) '\0')) {
  116. //
  117. // Nobody logged on.
  118. //
  119. *BufPtr = NULL;
  120. *EntriesRead = 0;
  121. *TotalEntries = 0;
  122. } else {
  123. // These variables are used by the COPY_STRING macro.
  124. LPBYTE NewFixedEnd;
  125. LPTSTR NewStringTop;
  126. LPWKSTA_INFO_1 src = (LPVOID) OldInfo;
  127. LPWKSTA_USER_INFO_1 dest; // superset info level
  128. //
  129. // Allocate memory for native version of new info, which we'll
  130. // return to caller. (Caller must free it with NetApiBufferFree.)
  131. //
  132. Status = NetApiBufferAllocate(
  133. NewFixedSize + NewStringSize,
  134. (LPVOID *) & NewInfo);
  135. if (Status != NERR_Success) {
  136. goto Cleanup;
  137. }
  138. NetpAssert( NewInfo != NULL );
  139. IF_DEBUG(WKSTA) {
  140. NetpKdPrint(( PREFIX_NETAPI
  141. "RxNetWkstaUserEnum: allocated new buffer at "
  142. FORMAT_LPVOID "\n", (LPVOID) NewInfo ));
  143. }
  144. // Set up pointers for use by NetpCopyStringsToBuffer.
  145. dest = (LPVOID) NewInfo;
  146. NewStringTop = (LPTSTR) NetpPointerPlusSomeBytes(
  147. dest,
  148. NewFixedSize+NewStringSize);
  149. NewFixedEnd = NetpPointerPlusSomeBytes(NewInfo, NewFixedSize);
  150. #define COPY_STRING( InField, OutField ) \
  151. { \
  152. BOOL CopyOK; \
  153. NetpAssert( dest != NULL); \
  154. NetpAssert( src != NULL); \
  155. NetpAssert( (src -> InField) != NULL); \
  156. CopyOK = NetpCopyStringToBuffer ( \
  157. src->InField, \
  158. STRLEN(src->InField), \
  159. NewFixedEnd, \
  160. & NewStringTop, \
  161. & dest->OutField); \
  162. NetpAssert(CopyOK); \
  163. }
  164. //
  165. // Downlevel server, so one user is logged on.
  166. //
  167. *EntriesRead = 1;
  168. *TotalEntries = 1;
  169. //
  170. // Copy/convert data from OldInfo to NewInfo.
  171. //
  172. // User name is only field in level 0.
  173. COPY_STRING( wki1_username, wkui1_username );
  174. if (Level == 1) {
  175. // Do fields unique to level 1.
  176. COPY_STRING( wki1_logon_domain, wkui1_logon_domain );
  177. COPY_STRING( wki1_oth_domains, wkui1_oth_domains );
  178. COPY_STRING( wki1_logon_server, wkui1_logon_server );
  179. }
  180. NetpAssert( Level < 2 ); // Add code here someday?
  181. *BufPtr = NewInfo;
  182. }
  183. } else {
  184. // An error from RxpWkstaGetOldInfo()...
  185. NetpAssert( OldInfo == NULL );
  186. }
  187. Cleanup:
  188. if (OldInfo != NULL) {
  189. (void) NetApiBufferFree( OldInfo );
  190. }
  191. return (Status);
  192. } // RxNetWkstaUserEnum