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.

170 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SessCopy.c
  5. Abstract:
  6. This file contains RxpCopyAndConvertSessions().
  7. Author:
  8. John Rogers (JohnRo) 17-Oct-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. 17-Oct-1991 JohnRo
  14. Created.
  15. 21-Nov-1991 JohnRo
  16. Removed NT dependencies to reduce recompiles.
  17. 07-Feb-1992 JohnRo
  18. Fixed the infamous NetSessionEnum bug (where 1-2 sessions OK, 3 or
  19. more results in first few being trashed).
  20. Call NetApiBufferAllocate() instead of private version.
  21. --*/
  22. // These must be included first:
  23. #include <windef.h> // IN, DWORD, etc.
  24. #include <lmcons.h> // NET_API_STATUS, etc.
  25. #include <lmshare.h> // Required by rxsess.h.
  26. #include <rap.h> // LPDESC. (Needed by strucinf.h.)
  27. // These may be included in any order:
  28. #include <lmapibuf.h> // NetApiBufferAllocate().
  29. #include <lmerr.h> // ERROR_ and NERR_ equates.
  30. #include <netdebug.h> // DBGSTATIC, NetpKdPrint(()), FORMAT_ equates.
  31. #include <netlib.h> // NetpPointerPlusSomeBytes, etc.
  32. #include <rxpdebug.h> // IF_DEBUG().
  33. #include <rxsess.h> // My prototype.
  34. #include <strucinf.h> // NetpSessionStructureInfo().
  35. NET_API_STATUS
  36. RxpCopyAndConvertSessions(
  37. IN LPSESSION_SUPERSET_INFO InStructureArray,
  38. IN DWORD InEntryCount,
  39. IN DWORD LevelWanted,
  40. IN LPTSTR ClientName OPTIONAL,
  41. IN LPTSTR UserName OPTIONAL,
  42. OUT LPVOID * OutStructureArrayPtr, // alloc'ed by this routine
  43. OUT LPDWORD OutEntryCountPtr OPTIONAL
  44. )
  45. {
  46. LPSESSION_SUPERSET_INFO InEntry = InStructureArray;
  47. DWORD InEntriesLeft;
  48. const DWORD InFixedSize = sizeof(SESSION_SUPERSET_INFO);
  49. LPVOID OutEntry; // Buffer to be returned to caller.
  50. DWORD OutEntryCount;
  51. LPBYTE OutFixedDataEnd;
  52. DWORD OutFixedSize;
  53. DWORD OutMaxSize;
  54. LPTSTR OutStringLocation;
  55. DWORD OutStringSize;
  56. LPVOID OutStructureArray;
  57. BOOL AnyMatchFound = FALSE; // not yet.
  58. NET_API_STATUS Status;
  59. NetpAssert( InEntryCount > 0 );
  60. NetpAssert( InStructureArray != NULL );
  61. *OutStructureArrayPtr = NULL;
  62. NetpSetOptionalArg(OutEntryCountPtr, 0);
  63. //
  64. // Learn about info level that caller wants.
  65. //
  66. Status = NetpSessionStructureInfo (
  67. LevelWanted, // level to learn about
  68. PARMNUM_ALL, // No parmnum with this.
  69. TRUE, // Need native sizes.
  70. NULL, // don't need data desc 16
  71. NULL, // don't need data desc 32
  72. NULL, // don't need data desc SMB
  73. & OutMaxSize, // max buffer size (native)
  74. & OutFixedSize, // fixed size.
  75. & OutStringSize // string size.
  76. );
  77. if (Status != NERR_Success) {
  78. return (Status);
  79. }
  80. //
  81. // Allocate memory for 32-bit version of caller's info level.
  82. //
  83. Status = NetApiBufferAllocate(
  84. InEntryCount * OutMaxSize,
  85. & OutStructureArray);
  86. if (Status != NERR_Success) {
  87. return (Status);
  88. }
  89. OutEntry = OutStructureArray;
  90. IF_DEBUG(SESSION) {
  91. NetpKdPrint(( "RxpCopyAndConvertSessions: allocated output buffer at "
  92. FORMAT_LPVOID "\n", (LPVOID) OutStructureArray ));
  93. }
  94. OutEntryCount = 0;
  95. OutStringLocation = (LPTSTR) NetpPointerPlusSomeBytes(
  96. OutStructureArray, InEntryCount * OutMaxSize);
  97. for (InEntriesLeft=InEntryCount; InEntriesLeft > 0; --InEntriesLeft) {
  98. OutFixedDataEnd = NetpPointerPlusSomeBytes(
  99. OutEntry, OutFixedSize);
  100. if (RxpSessionMatches(
  101. (LPSESSION_SUPERSET_INFO) InEntry, // candidate structure
  102. ClientName,
  103. UserName)) {
  104. // Match!
  105. AnyMatchFound = TRUE;
  106. ++OutEntryCount;
  107. RxpConvertSessionInfo (
  108. InEntry,
  109. LevelWanted,
  110. OutEntry,
  111. OutFixedDataEnd,
  112. & OutStringLocation); // string area top (updated)
  113. OutEntry = (LPVOID) NetpPointerPlusSomeBytes(OutEntry,OutFixedSize);
  114. }
  115. InEntry = (LPVOID) NetpPointerPlusSomeBytes(InEntry, InFixedSize);
  116. }
  117. if (AnyMatchFound == FALSE) {
  118. (void) NetApiBufferFree( OutStructureArray );
  119. OutStructureArray = NULL;
  120. Status = RxpSessionMissingErrorCode( ClientName, UserName);
  121. } else {
  122. Status = NERR_Success;
  123. }
  124. //
  125. // Tell caller how things went.
  126. //
  127. *OutStructureArrayPtr = OutStructureArray;
  128. NetpSetOptionalArg(OutEntryCountPtr, OutEntryCount);
  129. return (Status);
  130. }