Source code of Windows XP (NT5)
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.

152 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. SessDel.c
  5. Abstract:
  6. This file contains RxNetSessionDel().
  7. Author:
  8. John Rogers (JohnRo) 18-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. 18-Oct-1991 JohnRo
  14. Created.
  15. 21-Oct-1991 JohnRo
  16. Fixed bug: RxNetSessionEnum wants BufPtr as "LPBYTE *".
  17. Added debug output.
  18. 27-Jan-1993 JohnRo
  19. RAID 8926: NetConnectionEnum to downlevel: memory leak on error.
  20. Use PREFIX_ equates.
  21. --*/
  22. // These must be included first:
  23. #include <windef.h> // IN, DWORD, etc.
  24. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  25. #include <lmshare.h> // Required by rxsess.h.
  26. // These may be included in any order:
  27. #include <apinums.h> // API_ equates.
  28. #include <lmapibuf.h> // NetApiBufferFree().
  29. #include <lmerr.h> // ERROR_ and NERR_ equates.
  30. #include <netdebug.h> // NetpKdPrint(), FORMAT_ equates.
  31. #include <prefix.h> // PREFIX_ equates.
  32. #include <rap.h> // LPDESC.
  33. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  34. #include <rx.h> // RxRemoteApi().
  35. #include <rxpdebug.h> // IF_DEBUG().
  36. #include <rxsess.h> // My prototype, RxpSession routines.
  37. NET_API_STATUS
  38. RxNetSessionDel (
  39. IN LPTSTR UncServerName,
  40. IN LPTSTR ClientName OPTIONAL,
  41. IN LPTSTR UserName OPTIONAL
  42. )
  43. {
  44. LPSESSION_SUPERSET_INFO ArrayPtr = NULL;
  45. DWORD EntryCount;
  46. NET_API_STATUS Status;
  47. DWORD TotalEntries;
  48. NetpAssert(UncServerName != NULL);
  49. NetpAssert(*UncServerName != '\0');
  50. //
  51. // In LM 2.0, there's no way to delete with UserName or delete all clients,
  52. // so we have to do an enum and find the sessions we want to delete.
  53. //
  54. Status = RxNetSessionEnum (
  55. UncServerName,
  56. ClientName,
  57. UserName,
  58. SESSION_SUPERSET_LEVEL,
  59. /*lint -save -e530 */ // (We know variable isn't initialized.)
  60. (LPBYTE *) (LPVOID *) & ArrayPtr,
  61. /*lint -restore */ // (Resume uninitialized variable checking.)
  62. 1024, // prefered maximum (arbitrary)
  63. & EntryCount,
  64. & TotalEntries,
  65. NULL); // no resume handle
  66. if (Status == NERR_Success) {
  67. NetpAssert( EntryCount == TotalEntries );
  68. IF_DEBUG(SESSION) {
  69. NetpKdPrint(( PREFIX_NETAPI
  70. "RxNetSessionDel: enum found " FORMAT_DWORD
  71. " entries in array at " FORMAT_LPVOID ".\n",
  72. EntryCount, (LPVOID) ArrayPtr ));
  73. }
  74. if (EntryCount > 0) {
  75. LPSESSION_SUPERSET_INFO EntryPtr = ArrayPtr;
  76. NET_API_STATUS WorstStatus = NERR_Success;
  77. for ( ; EntryCount > 0; --EntryCount) {
  78. IF_DEBUG(SESSION) {
  79. NetpKdPrint(( PREFIX_NETAPI
  80. "RxNetSessionDel: checking entry at "
  81. FORMAT_LPVOID ", count is " FORMAT_DWORD ".\n",
  82. (LPVOID) EntryPtr, EntryCount ));
  83. }
  84. if (RxpSessionMatches( EntryPtr, ClientName, UserName) ) {
  85. Status = RxRemoteApi(
  86. API_WSessionDel, // API number
  87. UncServerName,
  88. REMSmb_NetSessionDel_P, // parm desc
  89. NULL, // no data desc 16
  90. NULL, // no data desc 32
  91. NULL, // no data desc SMB
  92. NULL, // no aux desc 16
  93. NULL, // no aux desc 32
  94. NULL, // no aux desc SMB
  95. 0, // flags: normal
  96. // rest of API's arguments, in 32-bit LM2.x format:
  97. ClientName, // client computer name
  98. (DWORD) 0); // reserved.
  99. if (Status != NERR_Success) {
  100. WorstStatus = Status;
  101. }
  102. }
  103. ++EntryPtr;
  104. }
  105. Status = WorstStatus;
  106. } else {
  107. // No entries found.
  108. Status = RxpSessionMissingErrorCode( ClientName, UserName );
  109. }
  110. }
  111. if (ArrayPtr != NULL ) {
  112. (void) NetApiBufferFree( ArrayPtr );
  113. }
  114. return (Status);
  115. } // RxNetSessionDel