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.

314 lines
6.7 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. // validate incomming string lengths
  35. //
  36. if(ClientName!=NULL && StringCchLength(ClientName,1024,NULL) != S_OK) {
  37. return ERROR_INVALID_PARAMETER;
  38. }
  39. if(UserName!=NULL && StringCchLength(UserName,1024,NULL) != S_OK) {
  40. return ERROR_INVALID_PARAMETER;
  41. }
  42. //
  43. // Make sure that the caller has the access necessary for this
  44. // operation.
  45. //
  46. error = SsCheckAccess(
  47. &SsSessionSecurityObject,
  48. SRVSVC_SESSION_DELETE
  49. );
  50. if ( error != NO_ERROR ) {
  51. return ERROR_ACCESS_DENIED;
  52. }
  53. //
  54. // Translate zero-length strings to NULL pointers.
  55. //
  56. if ( (ClientName != NULL) && (*ClientName == L'\0') ) {
  57. ClientName = NULL;
  58. }
  59. if ( (UserName != NULL) && (*UserName == L'\0') ) {
  60. UserName = NULL;
  61. }
  62. //
  63. // Either the client name or the user name must be specified. It
  64. // is not legal to leave both NULL, as this would imply "log out all
  65. // users." If that's what you want, stop the server.
  66. //
  67. if ( ClientName == NULL && UserName == NULL ) {
  68. return ERROR_INVALID_PARAMETER;
  69. }
  70. //
  71. // Set up the request packet.
  72. //
  73. srp = SsAllocateSrp( );
  74. if ( srp == NULL ) {
  75. return ERROR_NOT_ENOUGH_MEMORY;
  76. }
  77. RtlInitUnicodeString( &srp->Name1, ClientName );
  78. RtlInitUnicodeString( &srp->Name2, UserName );
  79. //
  80. // Simply send the request on to the server.
  81. //
  82. error = SsServerFsControl( FSCTL_SRV_NET_SESSION_DEL, srp, NULL, 0 );
  83. SsFreeSrp( srp );
  84. return error;
  85. } // NetrSessionDel
  86. NET_API_STATUS NET_API_FUNCTION
  87. NetrSessionEnum (
  88. IN LPTSTR ServerName,
  89. IN LPTSTR ClientName OPTIONAL,
  90. IN LPTSTR UserName OPTIONAL,
  91. OUT PSESSION_ENUM_STRUCT InfoStruct,
  92. IN DWORD PreferredMaximumLength,
  93. OUT LPDWORD TotalEntries,
  94. IN OUT LPDWORD ResumeHandle OPTIONAL
  95. )
  96. /*++
  97. Routine Description:
  98. This routine communicates with the server FSD to implement the
  99. NetSessionEnum function.
  100. Arguments:
  101. None.
  102. Return Value:
  103. NET_API_STATUS - NO_ERROR or reason for failure.
  104. --*/
  105. {
  106. NET_API_STATUS error;
  107. PSERVER_REQUEST_PACKET srp;
  108. ACCESS_MASK desiredAccess;
  109. ServerName;
  110. //
  111. // validate incomming string lengths
  112. //
  113. if(ClientName!=NULL && StringCchLength(ClientName,1024,NULL) != S_OK) {
  114. return ERROR_INVALID_PARAMETER;
  115. }
  116. if(UserName!=NULL && StringCchLength(UserName,1024,NULL) != S_OK) {
  117. return ERROR_INVALID_PARAMETER;
  118. }
  119. //
  120. // Make sure we have basic sanity on our input parameters
  121. //
  122. if( !ARGUMENT_PRESENT( InfoStruct ) ||
  123. InfoStruct->SessionInfo.Level2 == NULL ||
  124. InfoStruct->SessionInfo.Level2->Buffer != NULL ) {
  125. return ERROR_INVALID_PARAMETER;
  126. }
  127. //
  128. // Make sure that the level is valid and determine the access
  129. // necessary for the level.
  130. //
  131. switch ( InfoStruct->Level ) {
  132. case 0:
  133. case 10:
  134. desiredAccess = SRVSVC_SESSION_USER_INFO_GET;
  135. break;
  136. case 1:
  137. case 2:
  138. case 502:
  139. desiredAccess = SRVSVC_SESSION_ADMIN_INFO_GET;
  140. break;
  141. default:
  142. return ERROR_INVALID_LEVEL;
  143. }
  144. //
  145. // Make sure that the caller has the access necessary for this
  146. // operation.
  147. //
  148. error = SsCheckAccess(
  149. &SsSessionSecurityObject,
  150. desiredAccess
  151. );
  152. if ( error != NO_ERROR ) {
  153. return ERROR_ACCESS_DENIED;
  154. }
  155. //
  156. // Translate zero-length strings to NULL pointers.
  157. //
  158. if ( (ClientName != NULL) && (*ClientName == L'\0') ) {
  159. ClientName = NULL;
  160. }
  161. if ( (UserName != NULL) && (*UserName == L'\0') ) {
  162. UserName = NULL;
  163. }
  164. //
  165. // Is a client name was specified, make sure client name starts with "\\"
  166. //
  167. if ( ARGUMENT_PRESENT( ClientName ) &&
  168. (ClientName[0] != L'\\' || ClientName[1] != L'\\' ) ) {
  169. return(NERR_InvalidComputer);
  170. }
  171. //
  172. // Set up the input parameters in the request buffer.
  173. //
  174. srp = SsAllocateSrp( );
  175. if ( srp == NULL ) {
  176. return ERROR_NOT_ENOUGH_MEMORY;
  177. }
  178. srp->Level = InfoStruct->Level;
  179. RtlInitUnicodeString( &srp->Name1, ClientName );
  180. RtlInitUnicodeString( &srp->Name2, UserName );
  181. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  182. srp->Parameters.Get.ResumeHandle = *ResumeHandle;
  183. } else {
  184. srp->Parameters.Get.ResumeHandle = 0;
  185. }
  186. //
  187. // Get the data from the server. This routine will allocate the
  188. // return buffer and handle the case where PreferredMaximumLength ==
  189. // -1.
  190. //
  191. error = SsServerFsControlGetInfo(
  192. FSCTL_SRV_NET_SESSION_ENUM,
  193. srp,
  194. (PVOID *)&InfoStruct->SessionInfo.Level2->Buffer,
  195. PreferredMaximumLength
  196. );
  197. //
  198. // Set up return information.
  199. //
  200. InfoStruct->SessionInfo.Level2->EntriesRead =
  201. srp->Parameters.Get.EntriesRead;
  202. if ( ARGUMENT_PRESENT( TotalEntries ) ) {
  203. *TotalEntries = srp->Parameters.Get.TotalEntries;
  204. }
  205. if ( srp->Parameters.Get.EntriesRead > 0 ) {
  206. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  207. *ResumeHandle = srp->Parameters.Get.ResumeHandle;
  208. }
  209. } else if ( *TotalEntries == 0 ) {
  210. //
  211. // Entries read and total entries is 0. If a client name or
  212. // username was specified, return the appropriate error.
  213. //
  214. if ( ARGUMENT_PRESENT( UserName ) ) {
  215. error = NERR_UserNotFound;
  216. } else if ( ARGUMENT_PRESENT( ClientName ) ) {
  217. error = NERR_ClientNameNotFound;
  218. }
  219. }
  220. SsFreeSrp( srp );
  221. return error;
  222. } // NetrSessionEnum