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.

305 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name :
  4. lsaux.hxx
  5. Abstract:
  6. This header declares all the auxiliary types, data and functions
  7. required for processing ls command in ftp service.
  8. Author:
  9. Murali R. Krishnan ( MuraliK ) 2-May-1995
  10. Environment:
  11. Win32 -- User Mode
  12. Project:
  13. FTP Server DLL
  14. Revision History:
  15. --*/
  16. # ifndef _LSAUX_HXX_
  17. # define _LSAUX_HXX_
  18. /************************************************************
  19. * Include Headers
  20. ************************************************************/
  21. # include "tsunami.hxx"
  22. /************************************************************
  23. * Type Definitions
  24. ************************************************************/
  25. /**********************************************************************
  26. * Symbolic Constants
  27. **********************************************************************/
  28. // Attribute query macros.
  29. #define IS_HIDDEN(dwAttrib) \
  30. ((((dwAttrib) & FILE_ATTRIBUTE_HIDDEN) == 0)? FALSE: TRUE)
  31. #define IS_SYSTEM(dwAttrib) \
  32. ((((dwAttrib) & FILE_ATTRIBUTE_SYSTEM) == 0)? FALSE: TRUE)
  33. #define IS_DIR(dwAttrib) \
  34. ((((dwAttrib) & FILE_ATTRIBUTE_DIRECTORY) == 0)? FALSE: TRUE)
  35. #define IS_EMPTY_PATH(pszPath) ((pszPath == NULL ) || ( *pszPath == '\0'))
  36. #define NULL_TIME(x) (((x).LowPart | (x).HighPart) == 0)
  37. #define NULL_FILE_TIME(x) (((x).dwLowDateTime | (x).dwHighDateTime) == 0)
  38. #define FILE_MODE_R 0x0001
  39. #define FILE_MODE_W 0x0002
  40. #define FILE_MODE_X 0x0004
  41. #define FILE_MODE_ALL 0x0007
  42. /**********************************************************************
  43. * Type Definitions
  44. **********************************************************************/
  45. enum LS_OUTPUT {
  46. LsOutputSingleColumn = 0, // -1 (default)
  47. LsOutputLongFormat, // -l
  48. MaxLsOutput // Must be last!
  49. };
  50. enum LS_SORT { // ls sorting method to be used.
  51. LsSortByName = 0, // (default)
  52. LsSortByWriteTime, // -t
  53. LsSortByCreationTime, // -c
  54. LsSortByAccessTime, // -u
  55. MaxLsSort // Must be last!
  56. };
  57. enum LS_STYLE {
  58. LsStyleMsDos = 0, // default
  59. LsStyleUnix,
  60. MaxLsStyle // Must be last!
  61. }; // enum LS_STYLE
  62. typedef struct _LS_OPTIONS // LS options set by switches.
  63. {
  64. LS_OUTPUT OutputFormat; // Output format.
  65. LS_SORT SortMethod; // Sorting method.
  66. BOOL fReverseSort; // Reverse sort order if TRUE.
  67. BOOL fDecorate; // Decorate dirs if TRUE (-F).
  68. BOOL fShowAll; // Show all files.
  69. BOOL fShowDotDot; // Show . and ..
  70. BOOL fRecursive; // Recursive listing (-R).
  71. BOOL fFourDigitYear; // Display 4 digit year.
  72. LS_STYLE lsStyle;
  73. } LS_OPTIONS;
  74. typedef struct _LS_FORMAT_INFO
  75. {
  76. //
  77. // stores information required for long formatting operations
  78. // Used for avoiding sending multiple parameters in function call
  79. // for formatting information.
  80. // Also allows to include/exclude information relevant for formatting
  81. //
  82. // Following information dont change often. They are directory specific
  83. // These are required only in non-MsDos ( UNIX) long format output.
  84. BOOL fVolumeReadable; // Is this volume readable?
  85. BOOL fVolumeWritable; // Is this volume writable?
  86. BOOL fFourDigitYear; // Display year in 4 digit
  87. WORD wCurrentYear; // current year required for UNIX format
  88. HANDLE hUserToken; // token for the user requesting info
  89. CHAR * pszPathPart; // pointer to null-terminated path part
  90. // following may change for each file in a directory
  91. const char * pszFileName; // name of the file
  92. SYSTEMTIME stFile; // time to be formatted for file
  93. const char * pszDecorate; // what is the decoration character?
  94. } LS_FORMAT_INFO;
  95. struct FTP_LS_FILTER_INFO {
  96. BOOL fFilterHidden; // should we filter off Hidden Files?
  97. BOOL fFilterSystem; // should we filter off System Files?
  98. BOOL fFilterDotDot; // should we filter off files starting with '.' ?
  99. // If case is ignored, then expression should be in upper case
  100. BOOL fIgnoreCase; // should we ignore case??
  101. BOOL fRegExpression; // supplied expression is a regular expression
  102. LPCSTR pszExpression; // the expression to be used for filename compare
  103. };
  104. /**************************************************
  105. * LS_BUFFER definition and functions
  106. **************************************************/
  107. class LS_BUFFER {
  108. public:
  109. LS_BUFFER( VOID)
  110. : m_pb ( NULL),
  111. m_cbTotal ( 0),
  112. m_cbCur ( 0)
  113. {}
  114. ~LS_BUFFER(VOID)
  115. { FreeBuffer(); }
  116. DWORD AllocateBuffer( DWORD cb)
  117. {
  118. m_pb = (BYTE *) TCP_ALLOC( cb);
  119. m_cbCur = 0;
  120. m_cbTotal = (m_pb != NULL) ? cb : 0;
  121. return ( m_pb == NULL) ? ERROR_NOT_ENOUGH_MEMORY : NO_ERROR;
  122. }
  123. VOID FreeBuffer( VOID)
  124. {
  125. if ( m_pb != NULL) {
  126. TCP_FREE( m_pb);
  127. m_pb = NULL;
  128. m_cbTotal = m_cbCur = 0;
  129. }
  130. }
  131. BYTE * QueryBufferPtr(VOID) const { return ( m_pb); }
  132. DWORD QueryCB(VOID) const { return (m_cbCur); }
  133. DWORD QueryRemainingCB(VOID) const { return ( m_cbTotal - m_cbCur); }
  134. VOID IncrementCB(IN DWORD cbUsed) { m_cbCur += cbUsed; }
  135. CHAR * QueryAppendPtr(VOID) { return (CHAR *) (m_pb + m_cbCur); }
  136. VOID ResetAppendPtr(VOID) { m_cbCur = 0; }
  137. CHAR * QueryBuffer(VOID) const { return (CHAR *) QueryBufferPtr(); }
  138. private:
  139. BYTE * m_pb;
  140. DWORD m_cbTotal;
  141. DWORD m_cbCur;
  142. }; // class LS_BUFFER
  143. # define DEFAULT_LS_BUFFER_ALLOC_SIZE ( 4096)
  144. # define MIN_LS_BUFFER_SIZE ( 2 * MAX_PATH)
  145. /**********************************************************************
  146. * Prototypes of Functions
  147. **********************************************************************/
  148. // comparison routines used for sorting of type (PFN_CMP_WIN32_FIND_DATA);
  149. int __cdecl
  150. CompareNamesInFileInfo(
  151. IN const void * pvFileInfo1,
  152. IN const void * pvFileInfo2
  153. );
  154. int __cdecl
  155. CompareNamesRevInFileInfo(
  156. IN const void * pvFileInfo1,
  157. IN const void * pvFileInfo2
  158. );
  159. int __cdecl
  160. CompareWriteTimesInFileInfo(
  161. IN const void * pvFileInfo1,
  162. IN const void * pvFileInfo2
  163. );
  164. int __cdecl
  165. CompareWriteTimesRevInFileInfo(
  166. IN const void * pvFileInfo1,
  167. IN const void * pvFileInfo2
  168. );
  169. int __cdecl
  170. CompareAccessTimesInFileInfo(
  171. IN const void * pvFileInfo1,
  172. IN const void * pvFileInfo2
  173. );
  174. int __cdecl
  175. CompareAccessTimesRevInFileInfo(
  176. IN const void * pvFileInfo1,
  177. IN const void * pvFileInfo2
  178. );
  179. int __cdecl
  180. CompareCreationTimesInFileInfo(
  181. IN const void * pvFileInfo1,
  182. IN const void * pvFileInfo2
  183. );
  184. int __cdecl
  185. CompareCreationTimesRevInFileInfo(
  186. IN const void * pvFileInfo1,
  187. IN const void * pvFileInfo2
  188. );
  189. DWORD
  190. ComputeModeBits(
  191. IN HANDLE hUserToken,
  192. IN const CHAR * pszPathPart,
  193. IN const WIN32_FIND_DATA * pfdInfo,
  194. IN LPDWORD pcLinks,
  195. IN BOOL fVolumeReadable,
  196. IN BOOL fVolumeWritable
  197. );
  198. APIERR
  199. ComputeFileInfo(
  200. IN HANDLE hUserToken,
  201. IN CHAR * pszFile,
  202. IN DWORD * pdwAccessGranted,
  203. IN DWORD * pcLinks
  204. );
  205. DWORD
  206. GetFsFlags( IN CHAR chDrive);
  207. APIERR
  208. GetDirectoryInfo(
  209. IN LPUSER_DATA pUserData,
  210. OUT TS_DIRECTORY_INFO * pTsDirInfo,
  211. IN CHAR * pszSearchPath,
  212. IN const FTP_LS_FILTER_INFO * pfls,
  213. IN PFN_CMP_WIN32_FIND_DATA pfnCompare
  214. );
  215. const FILETIME *
  216. PickFileTime(IN const WIN32_FIND_DATA * pfdInfo,
  217. IN const LS_OPTIONS * pOptions);
  218. # endif // _LSAUX_HXX_
  219. /************************ End of File ***********************/