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.

344 lines
7.1 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. // validate incomming string lengths
  93. //
  94. if(BasePath!=NULL && StringCchLength(BasePath,1024,NULL) != S_OK) {
  95. return ERROR_INVALID_PARAMETER;
  96. }
  97. if(UserName!=NULL && StringCchLength(UserName,1024,NULL) != S_OK) {
  98. return ERROR_INVALID_PARAMETER;
  99. }
  100. //
  101. // Make sure that the caller is allowed to set share information in the
  102. // server.
  103. //
  104. error = SsCheckAccess(
  105. &SsFileSecurityObject,
  106. SRVSVC_FILE_INFO_GET
  107. );
  108. if ( error != NO_ERROR ) {
  109. return ERROR_ACCESS_DENIED;
  110. }
  111. if( InfoStruct->FileInfo.Level3 == NULL ) {
  112. return ERROR_INVALID_PARAMETER;
  113. }
  114. return FileEnumCommon(
  115. BasePath,
  116. UserName,
  117. InfoStruct->Level,
  118. (LPBYTE *)&InfoStruct->FileInfo.Level3->Buffer,
  119. PreferredMaximumLength,
  120. &InfoStruct->FileInfo.Level3->EntriesRead,
  121. TotalEntries,
  122. ResumeHandle,
  123. FALSE
  124. );
  125. } // NetrFileEnum
  126. NET_API_STATUS NET_API_FUNCTION
  127. NetrFileGetInfo (
  128. IN LPTSTR ServerName,
  129. IN DWORD FileId,
  130. IN DWORD Level,
  131. OUT LPFILE_INFO InfoStruct
  132. )
  133. /*++
  134. Routine Description:
  135. This routine communicates with the server FSD to implement the
  136. NetFileGetInfo function.
  137. Arguments:
  138. None.
  139. Return Value:
  140. NET_API_STATUS - NO_ERROR or reason for failure.
  141. --*/
  142. {
  143. NET_API_STATUS error;
  144. ULONG entriesRead;
  145. ULONG totalEntries;
  146. ULONG resumeHandle = FileId;
  147. ServerName;
  148. //
  149. // Make sure that the caller is allowed to get file information in the
  150. // server.
  151. //
  152. error = SsCheckAccess(
  153. &SsFileSecurityObject,
  154. SRVSVC_FILE_INFO_GET
  155. );
  156. if ( error != NO_ERROR ) {
  157. return ERROR_ACCESS_DENIED;
  158. }
  159. error = FileEnumCommon(
  160. NULL,
  161. NULL,
  162. Level,
  163. (LPBYTE *)InfoStruct,
  164. (DWORD)-1,
  165. &entriesRead,
  166. &totalEntries,
  167. &resumeHandle,
  168. TRUE
  169. );
  170. if ( (error == NO_ERROR) && (entriesRead == 0) ) {
  171. return ERROR_FILE_NOT_FOUND;
  172. }
  173. SS_ASSERT( error != NO_ERROR || entriesRead == 1 );
  174. return error;
  175. } // NetrFileGetInfo
  176. NET_API_STATUS
  177. FileEnumCommon (
  178. IN LPTSTR BasePath,
  179. IN LPTSTR UserName,
  180. IN DWORD Level,
  181. OUT LPBYTE *Buffer,
  182. IN DWORD PreferredMaximumLength,
  183. OUT LPDWORD EntriesRead,
  184. OUT LPDWORD TotalEntries,
  185. IN OUT LPDWORD ResumeHandle OPTIONAL,
  186. IN BOOLEAN IsGetInfo
  187. )
  188. {
  189. NET_API_STATUS error;
  190. PSERVER_REQUEST_PACKET srp;
  191. //
  192. // Make sure that the level is valid.
  193. //
  194. if ( Level != 2 && Level != 3 ) {
  195. return ERROR_INVALID_LEVEL;
  196. }
  197. //
  198. // Set up the input parameters in the request buffer.
  199. //
  200. srp = SsAllocateSrp( );
  201. if ( srp == NULL ) {
  202. return ERROR_NOT_ENOUGH_MEMORY;
  203. }
  204. #ifdef UNICODE
  205. RtlInitUnicodeString( &srp->Name1, BasePath );
  206. RtlInitUnicodeString( &srp->Name2, UserName );
  207. #else
  208. {
  209. NTSTATUS status;
  210. OEM_STRING ansiString;
  211. RtlInitString( &ansiString, BasePath );
  212. status = RtlOemStringToUnicodeString( &srp->Name1, &ansiString, TRUE );
  213. RtlInitString( &ansiString, UserName );
  214. status = RtlOemStringToUnicodeString( &srp->Name2, &ansiString, TRUE );
  215. }
  216. #endif
  217. srp->Level = Level;
  218. if ( IsGetInfo ) {
  219. srp->Flags = SRP_RETURN_SINGLE_ENTRY;
  220. }
  221. if ( ARGUMENT_PRESENT( ResumeHandle ) ) {
  222. srp->Parameters.Get.ResumeHandle = *ResumeHandle;
  223. } else {
  224. srp->Parameters.Get.ResumeHandle = 0;
  225. }
  226. //
  227. // Get the data from the server. This routine will allocate the
  228. // return buffer and handle the case where PreferredMaximumLength ==
  229. // -1.
  230. //
  231. error = SsServerFsControlGetInfo(
  232. FSCTL_SRV_NET_FILE_ENUM,
  233. srp,
  234. (PVOID *)Buffer,
  235. PreferredMaximumLength
  236. );
  237. //
  238. // Set up return information. Only change the resume handle if at
  239. // least one entry was returned.
  240. //
  241. *EntriesRead = srp->Parameters.Get.EntriesRead;
  242. *TotalEntries = srp->Parameters.Get.TotalEntries;
  243. if ( *EntriesRead > 0 && ARGUMENT_PRESENT( ResumeHandle ) ) {
  244. *ResumeHandle = srp->Parameters.Get.ResumeHandle;
  245. }
  246. #ifndef UNICODE
  247. RtlFreeUnicodeString( &srp->Name1 );
  248. RtlFreeUnicodeString( &srp->Name2 );
  249. #endif
  250. SsFreeSrp( srp );
  251. return error;
  252. } // FileEnumCommon