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.

333 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. File.c
  5. Abstract:
  6. This module contains support for the File catagory of APIs for the
  7. NT server service.
  8. Author:
  9. David Treadwell (davidtr) 13-Feb-1991
  10. Revision History:
  11. --*/
  12. #include "srvsvcp.h"
  13. //
  14. // Forward declarations.
  15. //
  16. NET_API_STATUS
  17. FileEnumCommon (
  18. IN LPTSTR BasePath,
  19. IN LPTSTR UserName,
  20. IN DWORD Level,
  21. OUT LPBYTE *Buffer,
  22. IN DWORD PreferredMaximumLength,
  23. OUT LPDWORD EntriesRead,
  24. OUT LPDWORD TotalEntries,
  25. IN OUT LPDWORD ResumeHandle OPTIONAL,
  26. IN BOOLEAN IsGetInfo
  27. );
  28. NET_API_STATUS NET_API_FUNCTION
  29. NetrFileClose (
  30. IN LPTSTR ServerName,
  31. IN DWORD FileId
  32. )
  33. /*++
  34. Routine Description:
  35. This routine communicates with the server FSD and FSP to implement the
  36. NetFileClose function.
  37. Arguments:
  38. None.
  39. Return Value:
  40. NET_API_STATUS - NO_ERROR or reason for failure.
  41. --*/
  42. {
  43. NET_API_STATUS error;
  44. PSERVER_REQUEST_PACKET srp;
  45. ServerName;
  46. //
  47. // Make sure that the caller is allowed to close files in the server.
  48. //
  49. error = SsCheckAccess( &SsFileSecurityObject, SRVSVC_FILE_CLOSE );
  50. if ( error != NO_ERROR ) {
  51. return ERROR_ACCESS_DENIED;
  52. }
  53. //
  54. // Set up the request packet. We use the name buffer pointer to
  55. // hold the file ID of the file to close.
  56. //
  57. srp = SsAllocateSrp( );
  58. if ( srp == NULL ) {
  59. return ERROR_NOT_ENOUGH_MEMORY;
  60. }
  61. srp->Parameters.Get.ResumeHandle = FileId;
  62. //
  63. // Simply send the request on to the server.
  64. //
  65. error = SsServerFsControl( FSCTL_SRV_NET_FILE_CLOSE, srp, NULL, 0 );
  66. SsFreeSrp( srp );
  67. return error;
  68. } // NetrFileClose
  69. NET_API_STATUS NET_API_FUNCTION
  70. NetrFileEnum (
  71. IN LPTSTR ServerName,
  72. IN LPTSTR BasePath,
  73. IN LPTSTR UserName,
  74. OUT PFILE_ENUM_STRUCT InfoStruct,
  75. IN DWORD PreferredMaximumLength,
  76. OUT LPDWORD TotalEntries,
  77. IN OUT LPDWORD ResumeHandle OPTIONAL
  78. )
  79. /*++
  80. Routine Description:
  81. This routine communicates with the server FSD to implement the
  82. NetFileEnum function.
  83. Arguments:
  84. None.
  85. Return Value:
  86. NET_API_STATUS - NO_ERROR or reason for failure.
  87. --*/
  88. {
  89. NET_API_STATUS error;
  90. ServerName;
  91. //
  92. // Make sure that the caller is allowed to set share information in the
  93. // server.
  94. //
  95. error = SsCheckAccess(
  96. &SsFileSecurityObject,
  97. SRVSVC_FILE_INFO_GET
  98. );
  99. if ( error != NO_ERROR ) {
  100. return ERROR_ACCESS_DENIED;
  101. }
  102. if( InfoStruct->FileInfo.Level3 == NULL ) {
  103. return ERROR_INVALID_PARAMETER;
  104. }
  105. return FileEnumCommon(
  106. BasePath,
  107. UserName,
  108. InfoStruct->Level,
  109. (LPBYTE *)&InfoStruct->FileInfo.Level3->Buffer,
  110. PreferredMaximumLength,
  111. &InfoStruct->FileInfo.Level3->EntriesRead,
  112. TotalEntries,
  113. ResumeHandle,
  114. FALSE
  115. );
  116. } // NetrFileEnum
  117. NET_API_STATUS NET_API_FUNCTION
  118. NetrFileGetInfo (
  119. IN LPTSTR ServerName,
  120. IN DWORD FileId,
  121. IN DWORD Level,
  122. OUT LPFILE_INFO InfoStruct
  123. )
  124. /*++
  125. Routine Description:
  126. This routine communicates with the server FSD to implement the
  127. NetFileGetInfo function.
  128. Arguments:
  129. None.
  130. Return Value:
  131. NET_API_STATUS - NO_ERROR or reason for failure.
  132. --*/
  133. {
  134. NET_API_STATUS error;
  135. ULONG entriesRead;
  136. ULONG totalEntries;
  137. ULONG resumeHandle = FileId;
  138. ServerName;
  139. //
  140. // Make sure that the caller is allowed to get file information in the
  141. // server.
  142. //
  143. error = SsCheckAccess(
  144. &SsFileSecurityObject,
  145. SRVSVC_FILE_INFO_GET
  146. );
  147. if ( error != NO_ERROR ) {
  148. return ERROR_ACCESS_DENIED;
  149. }
  150. error = FileEnumCommon(
  151. NULL,
  152. NULL,
  153. Level,
  154. (LPBYTE *)InfoStruct,
  155. (DWORD)-1,
  156. &entriesRead,
  157. &totalEntries,
  158. &resumeHandle,
  159. TRUE
  160. );
  161. if ( (error == NO_ERROR) && (entriesRead == 0) ) {
  162. return ERROR_FILE_NOT_FOUND;
  163. }
  164. SS_ASSERT( error != NO_ERROR || entriesRead == 1 );
  165. return error;
  166. } // NetrFileGetInfo
  167. NET_API_STATUS
  168. FileEnumCommon (
  169. IN LPTSTR BasePath,
  170. IN LPTSTR UserName,
  171. IN DWORD Level,
  172. OUT LPBYTE *Buffer,
  173. IN DWORD PreferredMaximumLength,
  174. OUT LPDWORD EntriesRead,
  175. OUT LPDWORD TotalEntries,
  176. IN OUT LPDWORD ResumeHandle OPTIONAL,
  177. IN BOOLEAN IsGetInfo
  178. )
  179. {
  180. NET_API_STATUS error;
  181. PSERVER_REQUEST_PACKET srp;
  182. //
  183. // Make sure that the level is valid.
  184. //
  185. if ( Level != 2 && Level != 3 ) {
  186. return ERROR_INVALID_LEVEL;
  187. }
  188. //
  189. // Set up the input parameters in the request buffer.
  190. //
  191. srp = SsAllocateSrp( );
  192. if ( srp == NULL ) {
  193. return ERROR_NOT_ENOUGH_MEMORY;
  194. }
  195. #ifdef UNICODE
  196. RtlInitUnicodeString( &srp->Name1, BasePath );
  197. RtlInitUnicodeString( &srp->Name2, UserName );
  198. #else
  199. {
  200. NTSTATUS status;
  201. OEM_STRING ansiString;
  202. RtlInitString( &ansiString, BasePath );
  203. status = RtlOemStringToUnicodeString( &srp->Name1, &ansiString, TRUE );
  204. RtlInitString( &ansiString, UserName );
  205. status = RtlOemStringToUnicodeString( &srp->Name2, &ansiString, TRUE );
  206. }
  207. #endif
  208. srp->Level = Level;
  209. if ( IsGetInfo ) {
  210. srp->Flags = SRP_RETURN_SINGLE_ENTRY;
  211. }
  212. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  213. srp->Parameters.Get.ResumeHandle = *ResumeHandle;
  214. } else {
  215. srp->Parameters.Get.ResumeHandle = 0;
  216. }
  217. //
  218. // Get the data from the server. This routine will allocate the
  219. // return buffer and handle the case where PreferredMaximumLength ==
  220. // -1.
  221. //
  222. error = SsServerFsControlGetInfo(
  223. FSCTL_SRV_NET_FILE_ENUM,
  224. srp,
  225. (PVOID *)Buffer,
  226. PreferredMaximumLength
  227. );
  228. //
  229. // Set up return information. Only change the resume handle if at
  230. // least one entry was returned.
  231. //
  232. *EntriesRead = srp->Parameters.Get.EntriesRead;
  233. *TotalEntries = srp->Parameters.Get.TotalEntries;
  234. if ( *EntriesRead > 0 && ARGUMENT_PRESENT( ResumeHandle ) ) {
  235. *ResumeHandle = srp->Parameters.Get.ResumeHandle;
  236. }
  237. #ifndef UNICODE
  238. RtlFreeUnicodeString( &srp->Name1 );
  239. RtlFreeUnicodeString( &srp->Name2 );
  240. #endif
  241. SsFreeSrp( srp );
  242. return error;
  243. } // FileEnumCommon