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.

508 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: tempcore.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _TEMPCORE_H
  11. #define _TEMPCORE_H
  12. #include "stlutil.h"
  13. //////////////////////////////////////////////////////////////////////////////
  14. // Keywords for the INF file format
  15. extern LPCWSTR g_lpszTemplates;
  16. extern LPCWSTR g_lpszDelegationTemplates;
  17. extern LPCWSTR g_lpszDescription;
  18. extern LPCWSTR g_lpszAppliesToClasses;
  19. extern LPCWSTR g_lpszScope;
  20. extern LPCWSTR g_lpszControlRight;
  21. extern LPCWSTR g_lpszThisObject;
  22. extern LPCWSTR g_lpszObjectTypes;
  23. ////////////////////////////////////////////////////////////////////////////////
  24. #define _GRANT_ALL \
  25. (STANDARD_RIGHTS_REQUIRED | ACTRL_DS_CONTROL_ACCESS | \
  26. ACTRL_DS_CREATE_CHILD | ACTRL_DS_DELETE_CHILD | ACTRL_DS_LIST | ACTRL_DS_SELF | \
  27. ACTRL_DS_READ_PROP | ACTRL_DS_WRITE_PROP | ACTRL_DS_DELETE_TREE | ACTRL_DS_LIST_OBJECT)
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // global functions
  30. struct _ACCESS_BIT_MAP
  31. {
  32. LPCWSTR lpsz;
  33. ULONG fMask;
  34. };
  35. const _ACCESS_BIT_MAP* GetTemplateAccessRightsMap();
  36. void GetStringFromAccessMask(ULONG fAccessMask, wstring& szAccessMask);
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // CInfFile
  39. class CInfFile
  40. {
  41. public:
  42. CInfFile()
  43. {
  44. m_InfHandle = INVALID_HANDLE_VALUE;
  45. }
  46. ~CInfFile()
  47. {
  48. Close();
  49. }
  50. BOOL Open(LPCWSTR lpszFile)
  51. {
  52. Close();
  53. UINT nErrorLine = 0;
  54. m_InfHandle = ::SetupOpenInfFile( lpszFile, // PCTSTR FileName, // name of the INF to open
  55. NULL, // PCTSTR InfClass, // optional, the class of the INF file
  56. INF_STYLE_WIN4, // DWORD InfStyle, // specifies the style of the INF file
  57. &nErrorLine // PUINT ErrorLine // optional, receives error information
  58. );
  59. if (m_InfHandle == INVALID_HANDLE_VALUE)
  60. {
  61. TRACE(L"Failed to open file, line = %d\n", nErrorLine);
  62. return FALSE;
  63. }
  64. return TRUE;
  65. }
  66. void Close()
  67. {
  68. if(m_InfHandle != INVALID_HANDLE_VALUE)
  69. {
  70. ::SetupCloseInfFile(m_InfHandle);
  71. m_InfHandle = INVALID_HANDLE_VALUE;
  72. }
  73. }
  74. operator HINF() { return m_InfHandle; }
  75. private:
  76. HINF m_InfHandle;
  77. };
  78. ///////////////////////////////////////////////////////////////////////////////
  79. // CInfBase
  80. #define N_BUF_LEN 256
  81. class CInfBase
  82. {
  83. public:
  84. CInfBase(HINF InfHandle)
  85. {
  86. //ASSERT(InfHandle != INVALID_HANDLE_VALUE);
  87. m_InfHandle = InfHandle;
  88. m_szBuf[0] = NULL;
  89. }
  90. LPCWSTR GetBuf() { return m_szBuf; }
  91. protected:
  92. HINF m_InfHandle;
  93. WCHAR m_szBuf[N_BUF_LEN];
  94. };
  95. ///////////////////////////////////////////////////////////////////////////////
  96. // CInfLine
  97. class CInfLine : public CInfBase
  98. {
  99. public:
  100. CInfLine(HINF InfHandle) : CInfBase(InfHandle)
  101. {
  102. }
  103. BOOL Bind(LPCWSTR lpszSection, LPCWSTR lpszKey)
  104. {
  105. DWORD dwRequiredSize;
  106. if (!SetupGetLineText(NULL, m_InfHandle, lpszSection, lpszKey,
  107. m_szBuf, N_BUF_LEN, &dwRequiredSize))
  108. {
  109. m_szBuf[0] = NULL;
  110. return FALSE;
  111. }
  112. return TRUE;
  113. }
  114. };
  115. ///////////////////////////////////////////////////////////////////////////////
  116. // CInfList
  117. class CInfList : public CInfBase
  118. {
  119. public:
  120. CInfList(HINF InfHandle) : CInfBase(InfHandle)
  121. {
  122. m_iField = 0;
  123. }
  124. BOOL Bind(LPCWSTR lpszSection, LPCWSTR lpszKey)
  125. {
  126. if (SetupFindFirstLine(m_InfHandle, lpszSection, lpszKey, &m_Context))
  127. {
  128. m_iField = 1;
  129. return TRUE;
  130. }
  131. return FALSE;
  132. }
  133. BOOL MoveNext()
  134. {
  135. DWORD dwRequiredSize;
  136. if (!SetupGetStringField(&m_Context, m_iField, m_szBuf, N_BUF_LEN, &dwRequiredSize))
  137. {
  138. m_szBuf[0] = NULL;
  139. return FALSE;
  140. }
  141. m_iField++;
  142. return TRUE;
  143. }
  144. private:
  145. INFCONTEXT m_Context;
  146. UINT m_iField;
  147. };
  148. ///////////////////////////////////////////////////////////////////////////////
  149. // CInfSectionKeys
  150. class CInfSectionKeys : public CInfBase
  151. {
  152. public:
  153. CInfSectionKeys(HINF InfHandle) : CInfBase(InfHandle)
  154. {
  155. m_nLineCount = (ULONG) -1;
  156. m_iCurrLine = (ULONG) -1;
  157. }
  158. BOOL Bind(LPCWSTR lpszSection)
  159. {
  160. m_szSection = lpszSection ? lpszSection : L"";
  161. m_nLineCount = SetupGetLineCount(m_InfHandle, lpszSection);
  162. if (m_nLineCount <= 0)
  163. {
  164. return FALSE;
  165. }
  166. m_iCurrLine = 0;
  167. return TRUE;
  168. }
  169. BOOL MoveNext()
  170. {
  171. if (m_iCurrLine >= m_nLineCount)
  172. {
  173. return FALSE;
  174. }
  175. INFCONTEXT Context;
  176. if (!::SetupGetLineByIndex(m_InfHandle, m_szSection.c_str(), m_iCurrLine, &Context))
  177. return FALSE;
  178. DWORD dwRequiredSize;
  179. if (!::SetupGetStringField(&Context, 0, m_szBuf, N_BUF_LEN, &dwRequiredSize))
  180. {
  181. m_szBuf[0] = NULL;
  182. return FALSE;
  183. }
  184. m_iCurrLine++;
  185. return TRUE;
  186. }
  187. private:
  188. LONG m_nLineCount;
  189. LONG m_iCurrLine;
  190. wstring m_szSection;
  191. };
  192. ////////////////////////////////////////////////////////////////////////
  193. // CTemplatePermission
  194. class CTemplatePermission
  195. {
  196. public:
  197. CTemplatePermission()
  198. {
  199. m_szName = L"";
  200. m_fAccessMask = 0x0;
  201. m_szControlRight = L"";
  202. }
  203. void SetAccessMask(LPCWSTR lpszName, ULONG fAccessMask)
  204. {
  205. m_szName = lpszName;
  206. m_fAccessMask = fAccessMask;
  207. m_szControlRight = L"";
  208. }
  209. void SetControlRight(LPCWSTR lpszControlRight)
  210. {
  211. m_szName = L"";
  212. m_fAccessMask = 0x0;
  213. m_szControlRight = lpszControlRight;
  214. }
  215. LPCWSTR GetName() { return m_szName.c_str(); }
  216. LPCWSTR GetControlRight() { return m_szControlRight.c_str();}
  217. ULONG GetAccessMask() { return m_fAccessMask;}
  218. #ifdef _DUMP
  219. void Dump()
  220. {
  221. wstring szAccessMask;
  222. GetStringFromAccessMask(GetAccessMask(), szAccessMask);
  223. TRACE(L" Right: name = <%s> mask = 0x%x (%s) control right = <%s>\n",
  224. GetName(), GetAccessMask(), szAccessMask.c_str(), GetControlRight());
  225. }
  226. #endif // _DUMP
  227. private:
  228. wstring m_szName;
  229. ULONG m_fAccessMask;
  230. wstring m_szControlRight;
  231. };
  232. ////////////////////////////////////////////////////////////////////////
  233. // CTemplatePermissionList
  234. class CTemplatePermissionList : public CPtrList<CTemplatePermission*>
  235. {
  236. public:
  237. CTemplatePermissionList(BOOL bOwnMem = TRUE) : CPtrList<CTemplatePermission*>(bOwnMem)
  238. {
  239. }
  240. };
  241. ////////////////////////////////////////////////////////////////////////
  242. // CTemplateObjectType
  243. class CTemplateObjectType
  244. {
  245. public:
  246. CTemplateObjectType(LPCWSTR lpszObjectName)
  247. {
  248. m_szObjectName = lpszObjectName;
  249. }
  250. LPCWSTR GetObjectName() { return m_szObjectName.c_str(); }
  251. CTemplatePermissionList* GetPermissionList() { return &m_permissionList; }
  252. #ifdef _DUMP
  253. void Dump()
  254. {
  255. TRACE(L" ObjectType: <%s>\n", GetObjectName());
  256. m_permissionList.Dump();
  257. }
  258. #endif // _DUMP
  259. private:
  260. wstring m_szObjectName;
  261. CTemplatePermissionList m_permissionList;
  262. };
  263. ////////////////////////////////////////////////////////////////////////
  264. // CTemplateObjectTypeList
  265. class CTemplateObjectTypeList : public CPtrList<CTemplateObjectType*>
  266. {
  267. public:
  268. CTemplateObjectTypeList(BOOL bOwnMem = TRUE) : CPtrList<CTemplateObjectType*>(bOwnMem)
  269. {
  270. }
  271. };
  272. class CTemplateObjectTypeListRef : public CTemplateObjectTypeList
  273. {
  274. public:
  275. CTemplateObjectTypeListRef() : CTemplateObjectTypeList(FALSE) {}
  276. };
  277. ////////////////////////////////////////////////////////////////////////
  278. // CTemplate
  279. class CTemplate
  280. {
  281. public:
  282. CTemplate(LPCWSTR lpszDescription)
  283. {
  284. m_szDescription = lpszDescription;
  285. m_bSelected = FALSE;
  286. }
  287. LPCWSTR GetDescription() { return m_szDescription.c_str(); }
  288. CTemplateObjectTypeList* GetObjectTypeList() { return &m_objectTypeList; }
  289. void AddAppliesToClass(LPCWSTR lpszClass)
  290. {
  291. m_appliestToClassesList.push_back(lpszClass);
  292. }
  293. BOOL AppliesToClass(LPCWSTR lpszClass)
  294. {
  295. if (m_appliestToClassesList.size() == 0)
  296. {
  297. // no classes, applies to all
  298. return TRUE;
  299. }
  300. // some classes on the list
  301. list<wstring>::iterator i;
  302. for (i = m_appliestToClassesList.begin(); i != m_appliestToClassesList.end(); ++i)
  303. {
  304. if (wcscmp((*i).c_str(), lpszClass) == 0)
  305. {
  306. return TRUE;
  307. }
  308. }
  309. return FALSE;
  310. }
  311. #ifdef _DUMP
  312. void Dump()
  313. {
  314. TRACE(L"\n Template Description: <%s>\n", GetDescription());
  315. if (m_appliestToClassesList.size() > 0)
  316. {
  317. list<wstring>::iterator i;
  318. TRACE(L" Applies To Classes: ");
  319. for (i = m_appliestToClassesList.begin(); i != m_appliestToClassesList.end(); ++i)
  320. {
  321. TRACE(L"<%s>", (*i).c_str());
  322. }
  323. TRACE(L"\n");
  324. }
  325. m_objectTypeList.Dump();
  326. }
  327. #endif // _DUMP
  328. public:
  329. BOOL m_bSelected;
  330. private:
  331. wstring m_szDescription;
  332. CTemplateObjectTypeList m_objectTypeList;
  333. list<wstring> m_appliestToClassesList;
  334. };
  335. ////////////////////////////////////////////////////////////////////////
  336. // CTemplateList
  337. class CTemplateList : public CPtrList<CTemplate*>
  338. {
  339. public:
  340. CTemplateList(BOOL bOwnMem = TRUE) : CPtrList<CTemplate*>(bOwnMem)
  341. {
  342. }
  343. };
  344. ////////////////////////////////////////////////////////////////////////
  345. // CTemplateManager
  346. class CTemplateManager
  347. {
  348. public:
  349. CTemplateManager()
  350. {
  351. }
  352. CTemplateList* GetTemplateList() { return &m_templateList; }
  353. BOOL Load(LPCWSTR lpszFileName)
  354. {
  355. TRACE(L"CTemplateManager::Load(%s)\n", lpszFileName);
  356. m_templateList.Clear();
  357. CInfFile file;
  358. if (!file.Open(lpszFileName))
  359. {
  360. TRACE(L"CTemplateManager::Load(%s) failed on INF file open\n", lpszFileName);
  361. return FALSE;
  362. }
  363. return _LoadTemplateList(file);
  364. }
  365. #ifdef _DUMP
  366. void Dump()
  367. {
  368. TRACE(L"TEMPLATE LIST DUMP BEGIN\n");
  369. m_templateList.Dump();
  370. TRACE(L"TEMPLATE LIST DUMP END\n");
  371. }
  372. #endif // _DUMP
  373. BOOL HasTemplates(LPCWSTR lpszClass);
  374. BOOL HasSelectedTemplates();
  375. void DeselectAll();
  376. private:
  377. void _LoadTemplatePermission(HINF InfHandle,
  378. LPCWSTR lpszPermissionSection,
  379. LPCWSTR lpszPermission,
  380. CTemplateObjectType* pObjectType);
  381. void _LoadTemplatePermissionsSection(HINF InfHandle,
  382. LPCWSTR lpszTemplateName,
  383. LPCWSTR lpszObject,
  384. CTemplate* pTemplate);
  385. void _LoadTemplate(HINF InfHandle, LPCWSTR lpszTemplateName);
  386. BOOL _LoadTemplateList(HINF InfHandle);
  387. CTemplateList m_templateList;
  388. };
  389. #endif // _TEMPCORE_H