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.

292 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. Sess.c
  5. Abstract:
  6. This module contains support for the Session catagory of APIs for the
  7. NT server service.
  8. Author:
  9. David Treadwell (davidtr) 30-Jan-1991
  10. Revision History:
  11. --*/
  12. #include "srvsvcp.h"
  13. #include <lmerr.h>
  14. NET_API_STATUS NET_API_FUNCTION
  15. NetrSessionDel (
  16. IN LPTSTR ServerName,
  17. IN LPTSTR ClientName OPTIONAL,
  18. IN LPTSTR UserName OPTIONAL
  19. )
  20. /*++
  21. Routine Description:
  22. This routine communicates with the server FSD to implement the
  23. NetSessionDel function.
  24. Arguments:
  25. None.
  26. Return Value:
  27. NET_API_STATUS - NO_ERROR or reason for failure.
  28. --*/
  29. {
  30. NET_API_STATUS error;
  31. PSERVER_REQUEST_PACKET srp;
  32. ServerName;
  33. //
  34. // Make sure that the caller has the access necessary for this
  35. // operation.
  36. //
  37. error = SsCheckAccess(
  38. &SsSessionSecurityObject,
  39. SRVSVC_SESSION_DELETE
  40. );
  41. if ( error != NO_ERROR ) {
  42. return ERROR_ACCESS_DENIED;
  43. }
  44. //
  45. // Translate zero-length strings to NULL pointers.
  46. //
  47. if ( (ClientName != NULL) && (*ClientName == L'\0') ) {
  48. ClientName = NULL;
  49. }
  50. if ( (UserName != NULL) && (*UserName == L'\0') ) {
  51. UserName = NULL;
  52. }
  53. //
  54. // Either the client name or the user name must be specified. It
  55. // is not legal to leave both NULL, as this would imply "log out all
  56. // users." If that's what you want, stop the server.
  57. //
  58. if ( ClientName == NULL && UserName == NULL ) {
  59. return ERROR_INVALID_PARAMETER;
  60. }
  61. //
  62. // Set up the request packet.
  63. //
  64. srp = SsAllocateSrp( );
  65. if ( srp == NULL ) {
  66. return ERROR_NOT_ENOUGH_MEMORY;
  67. }
  68. RtlInitUnicodeString( &srp->Name1, ClientName );
  69. RtlInitUnicodeString( &srp->Name2, UserName );
  70. //
  71. // Simply send the request on to the server.
  72. //
  73. error = SsServerFsControl( FSCTL_SRV_NET_SESSION_DEL, srp, NULL, 0 );
  74. SsFreeSrp( srp );
  75. return error;
  76. } // NetrSessionDel
  77. NET_API_STATUS NET_API_FUNCTION
  78. NetrSessionEnum (
  79. IN LPTSTR ServerName,
  80. IN LPTSTR ClientName OPTIONAL,
  81. IN LPTSTR UserName OPTIONAL,
  82. OUT PSESSION_ENUM_STRUCT InfoStruct,
  83. IN DWORD PreferredMaximumLength,
  84. OUT LPDWORD TotalEntries,
  85. IN OUT LPDWORD ResumeHandle OPTIONAL
  86. )
  87. /*++
  88. Routine Description:
  89. This routine communicates with the server FSD to implement the
  90. NetSessionEnum function.
  91. Arguments:
  92. None.
  93. Return Value:
  94. NET_API_STATUS - NO_ERROR or reason for failure.
  95. --*/
  96. {
  97. NET_API_STATUS error;
  98. PSERVER_REQUEST_PACKET srp;
  99. ACCESS_MASK desiredAccess;
  100. ServerName;
  101. //
  102. // Make sure we have basic sanity on our input parameters
  103. //
  104. if( !ARGUMENT_PRESENT( InfoStruct ) ||
  105. InfoStruct->SessionInfo.Level2 == NULL ||
  106. InfoStruct->SessionInfo.Level2->Buffer != NULL ) {
  107. return ERROR_INVALID_PARAMETER;
  108. }
  109. //
  110. // Make sure that the level is valid and determine the access
  111. // necessary for the level.
  112. //
  113. switch ( InfoStruct->Level ) {
  114. case 0:
  115. case 10:
  116. desiredAccess = SRVSVC_SESSION_USER_INFO_GET;
  117. break;
  118. case 1:
  119. case 2:
  120. case 502:
  121. desiredAccess = SRVSVC_SESSION_ADMIN_INFO_GET;
  122. break;
  123. default:
  124. return ERROR_INVALID_LEVEL;
  125. }
  126. //
  127. // Make sure that the caller has the access necessary for this
  128. // operation.
  129. //
  130. error = SsCheckAccess(
  131. &SsSessionSecurityObject,
  132. desiredAccess
  133. );
  134. if ( error != NO_ERROR ) {
  135. return ERROR_ACCESS_DENIED;
  136. }
  137. //
  138. // Translate zero-length strings to NULL pointers.
  139. //
  140. if ( (ClientName != NULL) && (*ClientName == L'\0') ) {
  141. ClientName = NULL;
  142. }
  143. if ( (UserName != NULL) && (*UserName == L'\0') ) {
  144. UserName = NULL;
  145. }
  146. //
  147. // Is a client name was specified, make sure client name starts with "\\"
  148. //
  149. if ( ARGUMENT_PRESENT( ClientName ) &&
  150. (ClientName[0] != L'\\' || ClientName[1] != L'\\' ) ) {
  151. return(NERR_InvalidComputer);
  152. }
  153. //
  154. // Set up the input parameters in the request buffer.
  155. //
  156. srp = SsAllocateSrp( );
  157. if ( srp == NULL ) {
  158. return ERROR_NOT_ENOUGH_MEMORY;
  159. }
  160. srp->Level = InfoStruct->Level;
  161. RtlInitUnicodeString( &srp->Name1, ClientName );
  162. RtlInitUnicodeString( &srp->Name2, UserName );
  163. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  164. srp->Parameters.Get.ResumeHandle = *ResumeHandle;
  165. } else {
  166. srp->Parameters.Get.ResumeHandle = 0;
  167. }
  168. //
  169. // Get the data from the server. This routine will allocate the
  170. // return buffer and handle the case where PreferredMaximumLength ==
  171. // -1.
  172. //
  173. error = SsServerFsControlGetInfo(
  174. FSCTL_SRV_NET_SESSION_ENUM,
  175. srp,
  176. (PVOID *)&InfoStruct->SessionInfo.Level2->Buffer,
  177. PreferredMaximumLength
  178. );
  179. //
  180. // Set up return information.
  181. //
  182. InfoStruct->SessionInfo.Level2->EntriesRead =
  183. srp->Parameters.Get.EntriesRead;
  184. if ( ARGUMENT_PRESENT( TotalEntries ) ) {
  185. *TotalEntries = srp->Parameters.Get.TotalEntries;
  186. }
  187. if ( srp->Parameters.Get.EntriesRead > 0 ) {
  188. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  189. *ResumeHandle = srp->Parameters.Get.ResumeHandle;
  190. }
  191. } else if ( *TotalEntries == 0 ) {
  192. //
  193. // Entries read and total entries is 0. If a client name or
  194. // username was specified, return the appropriate error.
  195. //
  196. if ( ARGUMENT_PRESENT( UserName ) ) {
  197. error = NERR_UserNotFound;
  198. } else if ( ARGUMENT_PRESENT( ClientName ) ) {
  199. error = NERR_ClientNameNotFound;
  200. }
  201. }
  202. SsFreeSrp( srp );
  203. return error;
  204. } // NetrSessionEnum