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.

248 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1987-91 Microsoft Corporation
  3. Module Name:
  4. FileEnum.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the File APIs.
  7. Author:
  8. John Rogers (JohnRo) 05-Sep-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. 05-Sep-1991 JohnRo
  14. Created.
  15. 21-Nov-1991 JohnRo
  16. Removed NT dependencies to reduce recompiles.
  17. --*/
  18. // These must be included first:
  19. #include <windef.h> // IN, DWORD, etc.
  20. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  21. // These may be included in any order:
  22. #include <apinums.h> // API_ equates.
  23. #include <lmerr.h> // ERROR_ and NERR_ equates.
  24. #include <netdebug.h> // NetpAssert(), NetpKdPrint(()).
  25. #include <netlib.h> // NetpMemoryAllocate(), NetpMemoryFree().
  26. #include <rap.h> // LPDESC.
  27. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  28. #include <rx.h> // RxRemoteApi().
  29. #include <rxfile.h> // My prototype(s).
  30. #include <rxpdebug.h> // IF_DEBUG().
  31. #include <string.h> // memset().
  32. #include <strucinf.h> // NetpFileStructureInfo().
  33. // Excerpts from LM 2.x Shares.h:
  34. //
  35. // typedef struct res_file_enum_2 FRK;
  36. //
  37. // #define FRK_INIT( f )
  38. // {
  39. // (f).res_pad = 0L;
  40. // (f).res_fs = 0;
  41. // (f).res_pro = 0;
  42. // }
  43. #define LM20_FRK_LEN 8
  44. #define LM20_FRK_INIT( f ) \
  45. { (void) memset( (f), '\0', LM20_FRK_LEN ); }
  46. NET_API_STATUS
  47. RxNetFileEnum (
  48. IN LPTSTR UncServerName,
  49. IN LPTSTR BasePath OPTIONAL,
  50. IN LPTSTR UserName OPTIONAL,
  51. IN DWORD Level,
  52. OUT LPBYTE *BufPtr,
  53. IN DWORD PreferedMaximumSize,
  54. OUT LPDWORD EntriesRead,
  55. OUT LPDWORD TotalEntries,
  56. IN OUT PDWORD_PTR ResumeHandle OPTIONAL
  57. )
  58. /*++
  59. Routine Description:
  60. RxNetFileEnum performs the same function as NetFileEnum,
  61. except that the server name is known to refer to a downlevel server.
  62. Arguments:
  63. (Same as NetFileEnum, except UncServerName must not be null, and
  64. must not refer to the local computer.)
  65. Return Value:
  66. (Same as NetFileEnum.)
  67. --*/
  68. {
  69. #define DumpResumeKey( label ) \
  70. { \
  71. IF_DEBUG(FILE) { \
  72. NetpKdPrint(( "RxNetFileEnum: resume key " label \
  73. " call to RxRemoteApi:\n" )); \
  74. NetpDbgHexDump( DownLevelResumeKey, LM20_FRK_LEN ); \
  75. } \
  76. }
  77. LPDESC DataDesc16;
  78. LPDESC DataDesc32;
  79. LPDESC DataDescSmb;
  80. LPBYTE DownLevelResumeKey;
  81. NET_API_STATUS Status;
  82. UNREFERENCED_PARAMETER(ResumeHandle);
  83. // Make sure caller didn't mess up.
  84. NetpAssert(UncServerName != NULL);
  85. if (BufPtr == NULL) {
  86. return (ERROR_INVALID_PARAMETER);
  87. }
  88. // Assume something might go wrong, and make error paths easier to
  89. // code. Also, check for a bad pointer before we do anything.
  90. *BufPtr = NULL;
  91. //
  92. // Set up downlevel resume handle.
  93. //
  94. NetpAssert( sizeof(DWORD) >= sizeof(LPVOID) );
  95. if (ResumeHandle != NULL) {
  96. if (*ResumeHandle == 0) {
  97. // First time through, so we have to allocate.
  98. DownLevelResumeKey = NetpMemoryAllocate( LM20_FRK_LEN );
  99. if (DownLevelResumeKey == NULL) {
  100. return (ERROR_NOT_ENOUGH_MEMORY);
  101. }
  102. *ResumeHandle = (DWORD_PTR) DownLevelResumeKey;
  103. LM20_FRK_INIT( DownLevelResumeKey );
  104. } else {
  105. // Use existing downlevel handle.
  106. DownLevelResumeKey = (LPBYTE) *ResumeHandle;
  107. }
  108. } else {
  109. // No resume handle, so create one temporarily.
  110. DownLevelResumeKey = NetpMemoryAllocate( LM20_FRK_LEN );
  111. if (DownLevelResumeKey == NULL) {
  112. return (ERROR_NOT_ENOUGH_MEMORY);
  113. }
  114. LM20_FRK_INIT( DownLevelResumeKey );
  115. }
  116. NetpAssert( DownLevelResumeKey != NULL );
  117. //
  118. // Get descriptors for this info level.
  119. //
  120. Status = NetpFileStructureInfo (
  121. Level,
  122. PARMNUM_ALL, // want all fields.
  123. TRUE, // want native sizes (really don't care)
  124. & DataDesc16,
  125. & DataDesc32,
  126. & DataDescSmb,
  127. NULL, // don't need max size
  128. NULL, // don't need fixed size
  129. NULL // don't need string size
  130. );
  131. if (Status != NERR_Success) {
  132. *BufPtr = NULL;
  133. return (Status);
  134. }
  135. NetpAssert( DataDesc16 != NULL );
  136. NetpAssert( DataDesc32 != NULL );
  137. NetpAssert( DataDescSmb != NULL );
  138. NetpAssert( *DataDesc16 != '\0' );
  139. NetpAssert( *DataDesc32 != '\0' );
  140. NetpAssert( *DataDescSmb != '\0' );
  141. if (DataDesc16) {
  142. NetpKdPrint(( "NetpFileStructureInfo: desc 16 is " FORMAT_LPDESC ".\n",
  143. DataDesc16 ));
  144. }
  145. if (DataDesc32) {
  146. NetpKdPrint(( "NetpFileStructureInfo: desc 32 is " FORMAT_LPDESC ".\n",
  147. DataDesc32 ));
  148. }
  149. if (DataDescSmb) {
  150. NetpKdPrint(( "NetpFileStructureInfo: desc Smb is " FORMAT_LPDESC ".\n",
  151. DataDescSmb ));
  152. }
  153. //
  154. // Remote the API, which will allocate the array for us.
  155. //
  156. DumpResumeKey( "before" );
  157. Status = RxRemoteApi(
  158. API_WFileEnum2, // api number
  159. UncServerName, // \\servername
  160. REMSmb_NetFileEnum2_P, // parm desc (SMB version)
  161. DataDesc16,
  162. DataDesc32,
  163. DataDescSmb,
  164. NULL, // no aux desc 16
  165. NULL, // no aux desc 32
  166. NULL, // no aux desc SMB
  167. ALLOCATE_RESPONSE, // we want array allocated for us
  168. // rest of API's arguments in 32-bit LM 2.x format:
  169. BasePath,
  170. UserName,
  171. Level, // sLevel: info level
  172. BufPtr, // pbBuffer: info lvl array (alloc for us)
  173. PreferedMaximumSize, // cbBuffer: info lvl array len
  174. EntriesRead, // pcEntriesRead
  175. TotalEntries, // pcTotalAvail
  176. DownLevelResumeKey, // pResumeKey (input)
  177. DownLevelResumeKey); // pResumeKey (output)
  178. DumpResumeKey( "after" );
  179. //
  180. // Clean up resume key if necessary.
  181. //
  182. if ( (Status != ERROR_MORE_DATA) || (ResumeHandle == NULL) ) {
  183. // Error or all done.
  184. NetpMemoryFree( DownLevelResumeKey );
  185. if (ResumeHandle != NULL) {
  186. *ResumeHandle = 0;
  187. }
  188. } else {
  189. // More to come, so leave handle open for caller.
  190. NetpAssert( (*ResumeHandle) == (DWORD_PTR) DownLevelResumeKey );
  191. }
  192. return (Status);
  193. } // RxNetFileEnum