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.

463 lines
14 KiB

  1. //
  2. // Microsoft Windows
  3. // Copyright (C) Microsoft Corporation, 1996-1999
  4. //
  5. // Author: DebiM
  6. // Date: September 1996
  7. //
  8. //--------------------------------------------------------
  9. #include "cstore.hxx"
  10. #define SCHEMA_VERSION_NUMBER 1740
  11. #define STRINGGUIDLEN 37
  12. #define STRINGGUIDRDNLEN 37+3
  13. #define SEARCHPAGESIZE 200
  14. #define PATHTYPESHIFT 29
  15. #define PATHTYPEMASK (0xFFFFFFFF << PATHTYPESHIFT)
  16. #define MAX_GUIDSTR_LEN 38
  17. typedef WCHAR STRINGGUID [STRINGGUIDLEN];
  18. typedef WCHAR STRINGGUIDRDN [STRINGGUIDRDNLEN];
  19. typedef FILETIME CSUSN;
  20. extern DWORD gCsOptions;
  21. int StringFromGUID(REFGUID rguid, LPWSTR lptsz);
  22. int RDNFromGUID(REFGUID rguid, LPWSTR lptsz);
  23. void GUIDFromString(LPWSTR psz,
  24. GUID *pclsguid);
  25. BOOL IsNullGuid(REFGUID rguid);
  26. DWORD NumDigits10(DWORD Value);
  27. BOOL GetGpoIdFromClassStorePath(
  28. WCHAR* wszClassStorePath,
  29. GUID* pGpoId);
  30. DWORD GetPropertyFromAttr(ADS_ATTR_INFO *pattr, DWORD cNum, WCHAR *szProperty);
  31. void FreeAttr(ADS_ATTR_INFO attr);
  32. void PackStrArrToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  33. WCHAR **pszAttr, DWORD num);
  34. void PackDWArrToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  35. DWORD *pAttr, DWORD num);
  36. void PackGUIDArrToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  37. GUID *pAttr, DWORD num);
  38. void PackStrToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  39. WCHAR *szAttr);
  40. void PackDWToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  41. DWORD Attr);
  42. void PackGUIDToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  43. GUID *pAttr);
  44. void PackBinToAttr(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  45. BYTE *pAttr, DWORD sz);
  46. void PackStrArrToAttrEx(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  47. WCHAR **pszAttr, DWORD num, BOOL APPEND);
  48. void PackDWArrToAttrEx(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  49. DWORD *pAttr, DWORD num, BOOL APPEND);
  50. void PackGUIDArrToAttrEx(ADS_ATTR_INFO *attr, WCHAR *szProperty,
  51. GUID *pAttr, DWORD num, BOOL APPEND);
  52. // ADS_ATTR_INFO structure is returned in GetObjectAttributes.
  53. // this is the same structure as columns but has different
  54. // fields and has unfortunately 1 unused different member.
  55. // this doesn't actually copy and hence should be freed if required
  56. // by the user but allocates an array of req'd size in case
  57. // of Unpack*Arr
  58. template <class AttrOrCol>
  59. HRESULT UnpackStrArrFrom(AttrOrCol AorC, WCHAR ***ppszAttr, DWORD *num)
  60. {
  61. DWORD i;
  62. *num = 0;
  63. *ppszAttr = (LPOLESTR *)CsMemAlloc(sizeof(LPOLESTR)*(AorC.dwNumValues));
  64. if (!(*ppszAttr))
  65. return E_OUTOFMEMORY;
  66. for (i = 0; (i < (AorC.dwNumValues)); i++)
  67. (*ppszAttr)[i] = AorC.pADsValues[i].DNString;
  68. *num = AorC.dwNumValues;
  69. return S_OK;
  70. }
  71. template <class AttrOrCol>
  72. HRESULT UnpackDWArrFrom(AttrOrCol AorC, DWORD **pAttr, DWORD *num)
  73. {
  74. DWORD i;
  75. ASSERT(AorC.dwADsType == ADSTYPE_INTEGER);
  76. *num = 0;
  77. *pAttr = (DWORD *)CsMemAlloc(sizeof(DWORD)*(AorC.dwNumValues));
  78. if (!(*pAttr))
  79. return E_OUTOFMEMORY;
  80. for (i = 0; (i < (AorC.dwNumValues)); i++)
  81. (*pAttr)[i] = (DWORD)AorC.pADsValues[i].Integer;
  82. *num = AorC.dwNumValues;
  83. return S_OK;
  84. }
  85. template <class AttrOrCol>
  86. HRESULT UnpackStrFrom(AttrOrCol AorC, WCHAR **pszAttr)
  87. {
  88. ASSERT(AorC.dwNumValues <= 1);
  89. if (AorC.dwNumValues)
  90. *pszAttr = AorC.pADsValues[0].DNString;
  91. else
  92. *pszAttr = NULL;
  93. return S_OK;
  94. }
  95. template <class AttrOrCol>
  96. HRESULT UnpackDWFrom(AttrOrCol AorC, DWORD *pAttr)
  97. {
  98. ASSERT(AorC.dwADsType == ADSTYPE_INTEGER);
  99. ASSERT(AorC.dwNumValues <= 1);
  100. if (AorC.dwNumValues)
  101. *pAttr = (DWORD)AorC.pADsValues[0].Integer;
  102. else
  103. *pAttr = 0;
  104. return S_OK;
  105. }
  106. template <class AttrOrCol>
  107. HRESULT UnpackStrArrAllocFrom(AttrOrCol AorC, WCHAR ***ppszAttr, DWORD *num)
  108. {
  109. DWORD i;
  110. ULONG ulNoBytes;
  111. *num = 0;
  112. *ppszAttr = (LPOLESTR *)CsMemAlloc(sizeof(LPOLESTR)*(AorC.dwNumValues));
  113. if (!(*ppszAttr))
  114. return E_OUTOFMEMORY;
  115. for (i = 0; (i < (AorC.dwNumValues)); i++) {
  116. HRESULT hr = E_OUTOFMEMORY;
  117. ulNoBytes = sizeof(WCHAR)*(1+wcslen(AorC.pADsValues[i].DNString));
  118. (*ppszAttr)[i] = (WCHAR *)CsMemAlloc(ulNoBytes);
  119. if ((*ppszAttr)[i])
  120. {
  121. hr = StringCbCopy((*ppszAttr)[i], ulNoBytes, AorC.pADsValues[i].DNString);
  122. if (FAILED(hr))
  123. {
  124. CsMemFree((*ppszAttr)[i]);
  125. (*ppszAttr)[i] = NULL;
  126. }
  127. }
  128. if (!((*ppszAttr)[i]))
  129. {
  130. DWORD iElement;
  131. //
  132. // If we run out of memory, we must free everything we
  133. // allocated previously
  134. //
  135. for ( iElement = 0; iElement < i; iElement++ )
  136. {
  137. CsMemFree( ((*ppszAttr)[iElement]) );
  138. }
  139. CsMemFree( *ppszAttr );
  140. *ppszAttr = NULL;
  141. return hr;
  142. }
  143. }
  144. *num = AorC.dwNumValues;
  145. return S_OK;
  146. }
  147. template <class AttrOrCol>
  148. HRESULT UnpackStrAllocFrom(AttrOrCol AorC, WCHAR **pszAttr)
  149. {
  150. ULONG ulNoBytes;
  151. HRESULT hr;
  152. ASSERT(AorC.dwNumValues <= 1);
  153. if (AorC.dwNumValues)
  154. {
  155. ulNoBytes = sizeof(WCHAR)*(wcslen(AorC.pADsValues[0].DNString)+1);
  156. *pszAttr = (LPOLESTR)CsMemAlloc(ulNoBytes);
  157. if (!(*pszAttr))
  158. return E_OUTOFMEMORY;
  159. hr = StringCbCopy(*pszAttr, ulNoBytes, AorC.pADsValues[0].DNString);
  160. if (FAILED(hr))
  161. {
  162. CsMemFree(*pszAttr);
  163. *pszAttr = NULL;
  164. return hr;
  165. }
  166. }
  167. else
  168. *pszAttr = NULL;
  169. return S_OK;
  170. }
  171. // GUIDS are not returned properly when using GetObjectAttributes.
  172. // Use only search when a GUID has to be returned.
  173. template <class AttrOrCol>
  174. HRESULT UnpackGUIDFrom(AttrOrCol AorC, GUID *pAttr)
  175. {
  176. ASSERT(AorC.dwNumValues <= 1);
  177. if (AorC.dwNumValues) {
  178. ASSERT(AorC.pADsValues[0].OctetString.dwLength == sizeof(GUID));
  179. memcpy(pAttr, AorC.pADsValues[0].OctetString.lpValue,
  180. AorC.pADsValues[0].OctetString.dwLength);
  181. }
  182. else
  183. memset((void *)(pAttr), 0, sizeof(GUID));
  184. return S_OK;
  185. }
  186. template <class AttrOrCol>
  187. HRESULT UnpackGUIDArrFrom(AttrOrCol AorC, GUID **pAttr, DWORD *num)
  188. {
  189. DWORD i;
  190. *pAttr = (GUID *)CsMemAlloc(sizeof(GUID)*AorC.dwNumValues);
  191. if (!(*pAttr))
  192. return E_OUTOFMEMORY;
  193. for (i = 0; i < (AorC.dwNumValues); i++)
  194. {
  195. ASSERT(AorC.pADsValues[i].OctetString.dwLength == sizeof(GUID));
  196. memcpy((*pAttr)+i, AorC.pADsValues[i].OctetString.lpValue,
  197. AorC.pADsValues[i].OctetString.dwLength);
  198. }
  199. *num = AorC.dwNumValues;
  200. return S_OK;
  201. }
  202. template <class AttrOrCol>
  203. HRESULT UnpackByteAllocFrom(AttrOrCol AorC, BYTE** ppAttr, UINT* pcbSize)
  204. {
  205. ASSERT(AorC.dwNumValues <= 1);
  206. if (AorC.dwNumValues) {
  207. *ppAttr = (BYTE*) CsMemAlloc(AorC.pADsValues[0].OctetString.dwLength);
  208. if ( ! *ppAttr )
  209. {
  210. return E_OUTOFMEMORY;
  211. }
  212. *pcbSize = AorC.pADsValues[0].OctetString.dwLength;
  213. memcpy(*ppAttr, AorC.pADsValues[0].OctetString.lpValue,
  214. AorC.pADsValues[0].OctetString.dwLength);
  215. }
  216. else
  217. *ppAttr = NULL;
  218. return S_OK;
  219. }
  220. inline LONG GetDsFlags()
  221. {
  222. LONG lFlags = ADS_SECURE_AUTHENTICATION | ADS_FAST_BIND;
  223. //
  224. // If a secure channel is specified, we need to add flags for
  225. // packet integrity
  226. //
  227. if ( gCsOptions & CsOption_AdminTool )
  228. return lFlags | GetADsOpenObjectFlags();
  229. else
  230. return lFlags | ADS_USE_SIGNING;
  231. }
  232. #define CLASSSTORE_EVENT_SOURCE L"Application Deployment"
  233. HRESULT RemapErrorCode(HRESULT ErrorCode, LPOLESTR szContainerName);
  234. void UnpackPlatform (DWORD *pdwArch, CSPLATFORM *pPlatform);
  235. void PackPlatform (DWORD dwArch, CSPLATFORM *pPlatform);
  236. ULONG FindDescription(LPOLESTR *desc, ULONG cdesc, LCID *plcid,
  237. LPOLESTR szDescription, BOOL GetPrimary);
  238. HRESULT GetCategoryLocaleDesc(LPOLESTR *pdesc, ULONG cdesc, LCID *plcid,
  239. LPOLESTR szDescription, ULONG ulSize);
  240. HRESULT CreateRepository(CServerContext* pServerContext,
  241. LPOLESTR szParentPath,
  242. LPOLESTR szStoreName,
  243. LPOLESTR szPolicyName);
  244. HRESULT DeleteRepository(CServerContext* pServerContext, LPOLESTR szParentPath, LPOLESTR szStoreName);
  245. HRESULT GetRootPath(CServerContext* pServerContext, WCHAR *szRootPath, ULONG ulSize);
  246. STDAPI
  247. ReleasePackageInfo(PACKAGEDISPINFO *PackageInfo);
  248. HRESULT GetPackageDetail (HANDLE hPackageADs,
  249. LPOLESTR szFullClassName,
  250. PACKAGEDETAIL *pPackageDetail);
  251. WCHAR* AllocGpoPathFromClassStorePath( WCHAR* pszClassStorePath );
  252. HRESULT
  253. GetEscapedNameFilter( WCHAR* wszName, WCHAR** ppwszEscapedName );
  254. void ReportEventCS(
  255. HRESULT ErrorCode,
  256. HRESULT ExtendedErrorCode,
  257. LPOLESTR szContainerName);
  258. #define LDAPPREFIX L"LDAP://"
  259. #define LDAPPREFIXLENGTH 7
  260. #define LDAPPATHSEP L","
  261. #define CLASS_CS_CONTAINER L"classStore"
  262. // #define CLASS_CS_CLASS L"classRegistration"
  263. #define CLASS_CS_PACKAGE L"packageRegistration"
  264. #define CLASS_CS_CATEGORY L"categoryRegistration"
  265. #define CLASSSTORECONTAINERNAME L"CN=Class Store"
  266. // #define CLASSCONTAINERNAME L"CN=Classes"
  267. #define PACKAGECONTAINERNAME L"CN=Packages"
  268. // #define CATEGORYCONTAINERNAME L"CN=Categories"
  269. #define APPCATEGORYCONTAINERNAME L"CN=AppCategories,CN=Default Domain Policy,CN=System,"
  270. //
  271. // ClassStoreContainer object propertynames
  272. //
  273. #define STOREVERSION L"appSchemaVersion"
  274. #define STOREUSN L"lastUpdateSequence"
  275. #define POLICYNAME L"extensionName"
  276. #define POLICYDN L"displayName"
  277. #define GPNAME L"displayName"
  278. //
  279. // Class object propertynames
  280. //
  281. #define PROGIDLIST L"cOMProgID"
  282. #define CLASSCLSID L"cOMCLSID"
  283. // #define TREATASCLSID L"cOMTreatAsClassId"
  284. #define IMPL_CATEGORIES L"implementedCategories"
  285. #define REQ_CATEGORIES L"requiredCategories"
  286. #define CLASSREFCOUNTER L"flags"
  287. //
  288. // Package object propertynames
  289. //
  290. // #define PKGTLBIDLIST L"cOMTypelibId"
  291. #define PKGCLSIDLIST L"cOMClassID"
  292. #define PKGPROGIDLIST L"cOMProgID"
  293. // #define PKGIIDLIST L"cOMInterfaceID"
  294. #define PKGFILEEXTNLIST L"fileExtPriority"
  295. #define LOCALEID L"localeID"
  296. #define ARCHLIST L"machineArchitecture"
  297. #define VERSIONHI L"versionNumberHi"
  298. #define VERSIONLO L"versionNumberLo"
  299. #define REVISION L"revision"
  300. #define PACKAGETYPE L"packageType"
  301. #define PACKAGEFLAGS L"packageFlags"
  302. #define PACKAGENAME L"packageName"
  303. #define SCRIPTPATH L"msiScriptPath"
  304. #define SEARCHFLAGS L"msiScriptName"
  305. #define SCRIPTSIZE L"msiScriptSize"
  306. #define HELPURL L"url"
  307. #define SETUPCOMMAND L"setupCommand"
  308. #define PKGUSN L"lastUpdateSequence"
  309. #define MSIFILELIST L"msiFileList"
  310. #define PKGCATEGORYLIST L"categories"
  311. #define UPGRADESPACKAGES L"canUpgradeScript"
  312. #define UILEVEL L"installUiLevel"
  313. #define PKGSCRIPT L"msiScript"
  314. #define PKGDISPLAYNAME L"displayName"
  315. #define PRODUCTCODE L"productCode"
  316. //
  317. // The mvipc attribute refers to a package property that Darwin uses
  318. // to describe upgrades supported by the package. The server side
  319. // app deployment UI uses this to generate a mandated upgrade relationship --
  320. // this attribute is written into the directory so that the UI can determine
  321. // if there are packages in the DS that should get upgraded by a deployed package.
  322. // This attribute is never used on the client side.
  323. //
  324. #define MVIPC L"upgradeProductCode"
  325. #define PUBLISHER L"vendor"
  326. #define SECURITYDESCRIPTOR L"nTSecurityDescriptor"
  327. //
  328. // Category object Propertynames
  329. //
  330. #define DESCRIPTION L"description"
  331. #define LOCALEDESCRIPTION L"localizedDescription"
  332. #define DEFAULT_LOCALE_ID L"localeID"
  333. #define CATEGORYCATID L"categoryId"
  334. #define OBJECTCLASS L"objectclass"
  335. #define OBJECTDN L"ADsPath"
  336. #define OBJECTGUID L"objectGUID"
  337. #define DEFAULTCLASSSTOREPATH L"defaultClassStore"
  338. #define CAT_DESC_DELIMITER L"::" // Between Locale & Desc in Category
  339. #define CAT_DESC_DELIM_LEN 2
  340. #define CAT_DESC_MAX_LEN 127 // Maximum size of a description
  341. #define PKG_UPG_DELIMITER1 L"\\\\" // Between Class Store Name & PkgGuid
  342. #define PKG_UPG_DELIM1_LEN 2
  343. #define PKG_UPG_DELIMITER2 L":" // Between PkgGuid & Flag
  344. #define PKG_UPG_DELIM2_LEN 1
  345. #define PKG_EMPTY_CLSID_VALUE L"00000000-0000-0000-0000-000000000000:0"
  346. extern LPOLESTR pszInstallInfoAttrNames[];
  347. extern DWORD cInstallInfoAttr;
  348. extern LPOLESTR pszPackageInfoAttrNames[];
  349. extern DWORD cPackageInfoAttr;
  350. extern LPOLESTR pszPackageDetailAttrNames[];
  351. extern DWORD cPackageDetailAttr;
  352. extern LPOLESTR pszDeleteAttrNames[];
  353. extern DWORD cDeleteAttr;
  354. extern LPOLESTR pszCategoryAttrNames[];
  355. extern DWORD cCategoryAttr;