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.

359 lines
12 KiB

  1. //=================================================================
  2. //
  3. // DllUtils.h
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #ifndef _DLL_UTILS_H_
  9. #define _DLL_UTILS_H_
  10. #define UNRECOGNIZED_VARIANT_TYPE FALSE
  11. #include "DllWrapperBase.h"
  12. #ifdef WIN9XONLY
  13. #include "Cim32NetApi.h"
  14. #endif
  15. #include "sid.h"
  16. #include <list>
  17. #ifdef UNICODE
  18. #define W2A(w, a, cb) lstrcpynW ( a, w, cb / sizeof ( WCHAR ) )
  19. #define TOBSTRT(x) x
  20. #else
  21. #define W2A(w, a, cb) WideCharToMultiByte( \
  22. CP_ACP, \
  23. 0, \
  24. w, \
  25. -1, \
  26. a, \
  27. cb, \
  28. NULL, \
  29. NULL)
  30. #define TOBSTRT(x) _bstr_t(x)
  31. #endif
  32. #define VWIN32_DIOC_DOS_IOCTL 1
  33. #define VWIN32_DIOC_DOS_INT13 4
  34. #define VWIN32_DIOC_DOS_DRIVEINFO 6
  35. #define CARRY_FLAG 0x1
  36. #define MAXITOA 18
  37. #define MAXI64TOA 33
  38. // In theory, this is defined in winnt.h, but not in our current one
  39. #ifndef FILE_ATTRIBUTE_ENCRYPTED
  40. #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
  41. #endif
  42. typedef std::list<CHString> CHStringList;
  43. typedef std::list<CHString>::iterator CHStringList_Iterator;
  44. // To Get Cim32NetApi
  45. #ifdef WIN9XONLY
  46. CCim32NetApi* WINAPI GetCim32NetApiPtr();
  47. void WINAPI FreeCim32NetApiPtr();
  48. #endif
  49. // platform identification
  50. DWORD WINAPI GetPlatformMajorVersion(void);
  51. DWORD WINAPI GetPlatformMinorVersion(void);
  52. DWORD WINAPI GetPlatformBuildNumber(void);
  53. #ifdef WIN9XONLY
  54. bool WINAPI IsWin95(void);
  55. bool WINAPI IsWin98(void);
  56. bool WINAPI IsMillennium(void);
  57. #endif
  58. #ifdef NTONLY
  59. bool WINAPI IsWinNT52(void);
  60. bool WINAPI IsWinNT51(void);
  61. bool WINAPI IsWinNT5(void);
  62. bool WINAPI IsWinNT351(void);
  63. bool WINAPI IsWinNT4(void);
  64. #endif
  65. // error logging
  66. void WINAPI LogEnumValueError( LPCWSTR szFile, DWORD dwLine, LPCWSTR szKey, LPCWSTR szId );
  67. void WINAPI LogOpenRegistryError( LPCWSTR szFile, DWORD dwLine, LPCWSTR szKey );
  68. void WINAPI LogError( LPCTSTR szFile, DWORD dwLine, LPCTSTR szKey );
  69. void WINAPI LogLastError( LPCTSTR szFile, DWORD dwLine );
  70. class CConfigMgrDevice;
  71. class CInstance;
  72. void WINAPI SetConfigMgrProperties(CConfigMgrDevice *pDevice, CInstance *pInstance);
  73. // map standard API return values (defined WinError.h)
  74. // to WBEMish hresults (defined in WbemCli.h)
  75. HRESULT WINAPI WinErrorToWBEMhResult(LONG error);
  76. #pragma pack(push, 1)
  77. typedef struct _DEVIOCTL_REGISTERS {
  78. DWORD reg_EBX;
  79. DWORD reg_EDX;
  80. DWORD reg_ECX;
  81. DWORD reg_EAX;
  82. DWORD reg_EDI;
  83. DWORD reg_ESI;
  84. DWORD reg_Flags;
  85. } DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS;
  86. typedef struct BPB { /* */
  87. WORD wBytesPerSector; // Bytes per sector
  88. BYTE btSectorsPerCluster; // Sectors per cluster
  89. WORD wReservedSectors; // Number of reserved sectors
  90. BYTE btNumFats; // Number of FATs
  91. WORD wEntriesInRoot; // Number of root-directory entries
  92. WORD wTotalSectors; // Total number of sectors
  93. BYTE btMediaIdByte; // Media descriptor
  94. WORD wSectorsPerFat; // Number of sectors per FAT
  95. WORD wSectorsPerTrack; // Number of sectors per track
  96. WORD wHeads; // Number of heads
  97. DWORD dwHiddenSecs; // Number of hidden sectors
  98. DWORD dwSectorsPerTrack; // Number of sectors if wTotalSectors == 0
  99. } BPB, *PBPB;
  100. typedef struct _DEVICEPARMS {
  101. BYTE btSpecialFunctions; // Special functions
  102. BYTE btDeviceType; // Device type
  103. WORD wDeviceAttribs; // Device attributes
  104. WORD wCylinders; // Number of cylinders
  105. BYTE btMediaType; // Media type
  106. // Beginning of BIOS parameter block (BPB)
  107. BPB stBPB;
  108. BYTE reserved[6]; //
  109. } DEVICEPARMS, *PDEVICEPARMS;
  110. typedef struct _A_BF_BPB {
  111. BPB stBPB;
  112. USHORT A_BF_BPB_BigSectorsPerFat; /* BigFAT Fat sectors */
  113. USHORT A_BF_BPB_BigSectorsPerFatHi; /* High word of BigFAT Fat sectrs */
  114. USHORT A_BF_BPB_ExtFlags; /* Other flags */
  115. USHORT A_BF_BPB_FS_Version; /* File system version */
  116. USHORT A_BF_BPB_RootDirStrtClus; /* Starting cluster of root directory */
  117. USHORT A_BF_BPB_RootDirStrtClusHi;
  118. USHORT A_BF_BPB_FSInfoSec; /* Sector number in the reserved */
  119. /* area where the BIGFATBOOTFSINFO */
  120. /* structure is. If this is >= */
  121. /* oldBPB.BPB_ReservedSectors or */
  122. /* == 0 there is no FSInfoSec */
  123. USHORT A_BF_BPB_BkUpBootSec; /* Sector number in the reserved */
  124. /* area where there is a backup */
  125. /* copy of all of the boot sectors */
  126. /* If this is >= */
  127. /* oldBPB.BPB_ReservedSectors or */
  128. /* == 0 there is no backup copy. */
  129. USHORT A_BF_BPB_Reserved[6]; /* Reserved for future expansion */
  130. } A_BF_BPB, *PA_BF_BPB;
  131. #define MAX_SECTORS_IN_TRACK 128 // MAXIMUM SECTORS ON A DISK.
  132. typedef struct A_SECTORTABLE {
  133. WORD ST_SECTORNUMBER;
  134. WORD ST_SECTORSIZE;
  135. } A_SECTORTABLE;
  136. typedef struct _EA_DEVICEPARAMETERS {
  137. BYTE btSpecialFunctions; // Special functions
  138. BYTE btDeviceType; // Device type
  139. WORD wDeviceAttribs; // Device attributes
  140. WORD dwCylinders; // Number of cylinders
  141. BYTE btMediaType; // Media type
  142. A_BF_BPB stBPB32; // Fat32 Bios parameter block
  143. BYTE RESERVED1[32];
  144. WORD EDP_TRACKTABLEENTRIES;
  145. A_SECTORTABLE stSectorTable[MAX_SECTORS_IN_TRACK];
  146. } EA_DEVICEPARAMETERS, *PEA_DEVICEPARAMETERS;
  147. typedef struct _DRIVE_MAP_INFO {
  148. BYTE btAllocationLength;
  149. BYTE btInfoLength;
  150. BYTE btFlags;
  151. BYTE btInt13Unit;
  152. DWORD dwAssociatedDriveMap;
  153. __int64 i64PartitionStartRBA;
  154. } DRIVE_MAP_INFO, *PDRIVE_MAP_INFO;
  155. typedef struct _ExtGetDskFreSpcStruc {
  156. WORD Size; // Size of structure (out)
  157. WORD Level; // Level (must be zero)
  158. DWORD SectorsPerCluster;
  159. DWORD BytesPerSector;
  160. DWORD AvailableClusters;
  161. DWORD TotalClusters;
  162. DWORD AvailablePhysSectors;
  163. DWORD TotalPhysSectors;
  164. DWORD AvailableAllocationUnits;
  165. DWORD TotalAllocationUnits;
  166. DWORD Rsvd1;
  167. DWORD Rsvd2;
  168. } ExtGetDskFreSpcStruc, *pExtGetDskFreSpcStruc;
  169. #pragma pack(pop)
  170. BOOL LoadStringW(CHString &sString, UINT nID);
  171. void Format(CHString &sString, UINT nFormatID, ...);
  172. void FormatMessageW(CHString &sString, UINT nFormatID, ...);
  173. int LoadStringW(UINT nID, LPWSTR lpszBuf, UINT nMaxBuf);
  174. #ifdef WIN9XONLY
  175. BOOL WINAPI GetDeviceParms(PDEVICEPARMS pstDeviceParms, UINT nDrive);
  176. BOOL WINAPI GetDeviceParmsFat32(PEA_DEVICEPARAMETERS pstDeviceParms, UINT nDrive);
  177. BOOL WINAPI GetDriveMapInfo(PDRIVE_MAP_INFO pDriveMapInfo, UINT nDrive);
  178. BOOL WINAPI VWIN32IOCTL(PDEVIOCTL_REGISTERS preg, DWORD dwCall);
  179. BYTE WINAPI GetBiosUnitNumberFromPNPID(CHString strDeviceID);
  180. #endif
  181. #ifdef NTONLY
  182. void WINAPI TranslateNTStatus( DWORD dwStatus, CHString & chsValue);
  183. BOOL WINAPI GetServiceFileName(LPCTSTR szService, CHString &strFileName);
  184. bool WINAPI GetServiceStatus( CHString a_chsService, CHString &a_chsStatus ) ;
  185. #endif
  186. void WINAPI ConfigStatusToCimStatus ( DWORD a_Status , CHString &a_StringStatus ) ;
  187. CHString WINAPI GetFileTypeDescription(LPCTSTR szExtension);
  188. bool WINAPI CompareVariantsNoCase(const VARIANT *v1, const VARIANT *v2);
  189. bool WINAPI GetManufacturerFromFileName(LPCTSTR szFile, CHString &strMfg);
  190. bool WINAPI GetVersionFromFileName(LPCTSTR szFile, CHString &strVersion);
  191. BOOL WINAPI EnablePrivilegeOnCurrentThread(LPCTSTR szPriv);
  192. bool WINAPI GetFileInfoBlock(LPCTSTR szFile, LPVOID *pInfo);
  193. bool WINAPI GetVarFromInfoBlock(LPVOID pInfo, LPCTSTR szVar, CHString &strValue);
  194. BOOL WINAPI GetVersionLanguage(void *vpInfo, WORD *wpLang, WORD *wpCodePage);
  195. BOOL WINAPI Get_ExtFreeSpace(BYTE btDriveName, ExtGetDskFreSpcStruc *pstExtGetDskFreSpcStruc);
  196. HRESULT WINAPI GetHKUserNames(CHStringList &list);
  197. VOID WINAPI EscapeBackslashes(CHString& chstrIn, CHString& chstrOut);
  198. VOID WINAPI EscapeQuotes(CHString& chstrIn, CHString& chstrOut);
  199. VOID WINAPI RemoveDoubleBackslashes(const CHString& chstrIn, CHString& chstrOut);
  200. CHString WINAPI RemoveDoubleBackslashes(const CHString& chstrIn);
  201. void WINAPI SetSinglePrivilegeStatusObject(MethodContext* pContext, const WCHAR* pPrivilege);
  202. bool WINAPI StrToIdentifierAuthority(const CHString& str, SID_IDENTIFIER_AUTHORITY& identifierAuthority);
  203. bool WINAPI WhackToken(CHString& str, CHString& token);
  204. PSID WINAPI StrToSID(const CHString& str);
  205. #ifdef WIN9XONLY
  206. class HoldSingleCim32NetPtr
  207. {
  208. public:
  209. HoldSingleCim32NetPtr();
  210. ~HoldSingleCim32NetPtr();
  211. static void WINAPI FreeCim32NetApiPtr();
  212. static CCim32NetApi* WINAPI GetCim32NetApiPtr();
  213. private:
  214. static CCritSec m_csCim32Net;
  215. static HINSTANCE m_spCim32NetApiHandle ;
  216. };
  217. #endif
  218. // Used to get WBEM time from a filename. We need this because FAT and NTFS
  219. // work differently.
  220. enum FT_ENUM
  221. {
  222. FT_CREATION_DATE,
  223. FT_MODIFIED_DATE,
  224. FT_ACCESSED_DATE
  225. };
  226. CHString WINAPI GetDateTimeViaFilenameFiletime(LPCTSTR szFilename, FILETIME *pFileTime);
  227. CHString WINAPI GetDateTimeViaFilenameFiletime(LPCTSTR szFilename, FT_ENUM ftWhich);
  228. CHString WINAPI GetDateTimeViaFilenameFiletime(BOOL bNTFS, FILETIME *pFileTime);
  229. // Used to validate a numbered device ID is OK.
  230. // Example: ValidateNumberedDeviceID("VideoController7", "VideoController", pdwWhich)
  231. // returns TRUE, pdwWhich = 7.
  232. // Example: ValidateNumberedDeviceID("BadDeviceID", "VideoController", pdwWhich)
  233. // returns FALSE, pdwWhich unchanged
  234. BOOL WINAPI ValidateNumberedDeviceID(LPCWSTR szDeviceID, LPCWSTR szTag, DWORD *pdwWhich);
  235. // Critical sections used by various classes.
  236. extern CCritSec g_csPrinter;
  237. extern CCritSec g_csSystemName;
  238. #ifdef WIN9XONLY
  239. extern CCritSec g_csVXD;
  240. #endif
  241. bool WINAPI DelayLoadDllExceptionFilter(PEXCEPTION_POINTERS pep);
  242. #ifdef NTONLY
  243. HRESULT CreatePageFile(
  244. LPCWSTR wstrPageFileName,
  245. const LARGE_INTEGER liInitial,
  246. const LARGE_INTEGER liMaximum,
  247. const CInstance& Instance);
  248. #endif
  249. #if NTONLY >= 5
  250. bool GetAllUsersName(CHString& chstrAllUsersName);
  251. bool GetDefaultUsersName(CHString& chstrDefaultUsersName);
  252. bool GetCommonStartup(CHString& chstrCommonStartup);
  253. #endif
  254. BOOL GetLocalizedNTAuthorityString(
  255. CHString& chstrNT_AUTHORITY);
  256. BOOL GetLocalizedBuiltInString(
  257. CHString& chstrBuiltIn);
  258. BOOL GetSysAccountNameAndDomain(
  259. PSID_IDENTIFIER_AUTHORITY a_pAuthority,
  260. CSid& a_accountsid,
  261. BYTE a_saCount = 0,
  262. DWORD a_dwSubAuthority1 = 0,
  263. DWORD a_dwSubAuthority2 = 0);
  264. // neccessary structures for GetFileVersionInfo
  265. #include <pshpack4.h>
  266. typedef struct tag_StringTable {
  267. WORD wLength;
  268. WORD wValueLength;
  269. WORD wType;
  270. WCHAR szKey[8];
  271. } StringTable;
  272. typedef struct tag_StringFileInfo {
  273. WORD wLength;
  274. WORD wValueLength;
  275. WORD wType;
  276. WCHAR szKey[ sizeof("StringFileInfo") ];
  277. StringTable Children;
  278. } StringFileInfo ;
  279. typedef struct tagVERHEAD {
  280. WORD wTotLen;
  281. WORD wValLen;
  282. WORD wType; /* always 0 */
  283. WCHAR szKey[(sizeof("VS_VERSION_INFO")+3)&~03];
  284. VS_FIXEDFILEINFO vsf;
  285. } VERHEAD ;
  286. #include <poppack.h>
  287. #endif