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.

490 lines
13 KiB

  1. #include "precomp.hxx"
  2. #include <iadm.h>
  3. #include "coiadm.hxx"
  4. extern ULONG g_dwRefCount;
  5. CADMCOMSrvFactoryW::CADMCOMSrvFactoryW()
  6. {
  7. m_dwRefCount=0;
  8. }
  9. CADMCOMSrvFactoryW::~CADMCOMSrvFactoryW()
  10. {
  11. }
  12. HRESULT
  13. CADMCOMSrvFactoryW::CreateInstance(
  14. IUnknown *pUnkOuter,
  15. REFIID riid,
  16. void ** ppObject
  17. )
  18. {
  19. // DBGPRINTF( (DBG_CONTEXT, "[CADMCOMSrvFactoryW::CreateInstance]\n"));
  20. HRESULT hresReturn = E_NOINTERFACE;
  21. if (pUnkOuter != NULL) {
  22. return CLASS_E_NOAGGREGATION;
  23. }
  24. if (IID_IUnknown==riid ||
  25. IID_IMSAdminBase_W==riid ||
  26. IID_IMSAdminBase2_W==riid ||
  27. IID_IMSAdminBase3_W==riid) {
  28. CADMCOMW *padmcomw = new CADMCOMW();
  29. if( padmcomw == NULL ) {
  30. hresReturn = E_OUTOFMEMORY;
  31. }
  32. else {
  33. hresReturn = padmcomw->GetStatus();
  34. if (SUCCEEDED(hresReturn)) {
  35. hresReturn = padmcomw->QueryInterface(riid, ppObject);
  36. if( FAILED(hresReturn) ) {
  37. DBGPRINTF( (DBG_CONTEXT, "[CADMCOMSrvFactoryW::CreateInstance] no I/F\n"));
  38. }
  39. }
  40. padmcomw->Release();
  41. }
  42. }
  43. return hresReturn;
  44. }
  45. HRESULT
  46. CADMCOMSrvFactoryW::LockServer(BOOL fLock)
  47. {
  48. if (fLock) {
  49. InterlockedIncrement((long *)&g_dwRefCount);
  50. }
  51. else {
  52. InterlockedDecrement((long *)&g_dwRefCount);
  53. }
  54. return NO_ERROR;
  55. }
  56. HRESULT
  57. CADMCOMSrvFactoryW::QueryInterface(
  58. REFIID riid,
  59. void **ppObject
  60. )
  61. {
  62. // DBGPRINTF( (DBG_CONTEXT, "[CADMCOMSrvFactoryW::QueryInterface]\n"));
  63. if (riid==IID_IUnknown || riid == IID_IClassFactory) {
  64. *ppObject = (IClassFactory *) this;
  65. }
  66. else {
  67. return E_NOINTERFACE;
  68. }
  69. AddRef();
  70. return NO_ERROR;
  71. }
  72. ULONG
  73. CADMCOMSrvFactoryW::AddRef(
  74. )
  75. {
  76. DWORD dwRefCount;
  77. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  78. InterlockedIncrement((long *)&g_dwRefCount);
  79. return dwRefCount;
  80. }
  81. ULONG
  82. CADMCOMSrvFactoryW::Release()
  83. {
  84. DWORD dwRefCount;
  85. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  86. InterlockedDecrement((long *)&g_dwRefCount);
  87. if (dwRefCount == 0) {
  88. delete this;
  89. }
  90. return dwRefCount;
  91. }
  92. STDAPI
  93. SetABOLaunchPermissions(
  94. HKEY hKey )
  95. {
  96. HRESULT hr = S_OK;
  97. DWORD dwError;
  98. BOOL fRet;
  99. SECURITY_DESCRIPTOR SecurityDesc = {0};
  100. SECURITY_DESCRIPTOR *pSelfRelative = NULL;
  101. DWORD cbSelfRelative = 0;
  102. EXPLICIT_ACCESS ea = {0};
  103. ACL *pAcl = NULL;
  104. SID *pSidAdmins = NULL;
  105. DWORD cbSidAdmins = SECURITY_MAX_SID_SIZE;
  106. // Initialize the security descriptor
  107. fRet = InitializeSecurityDescriptor( &SecurityDesc, SECURITY_DESCRIPTOR_REVISION );
  108. if ( !fRet )
  109. {
  110. dwError = GetLastError();
  111. hr = HRESULT_FROM_WIN32( dwError );
  112. goto exit;
  113. }
  114. // Allocate memory for the SID
  115. pSidAdmins = (SID*)LocalAlloc( LPTR, cbSidAdmins );
  116. if ( pSidAdmins == NULL )
  117. {
  118. hr = E_OUTOFMEMORY;
  119. goto exit;
  120. }
  121. // Create SID for Administrators
  122. fRet = CreateWellKnownSid( WinBuiltinAdministratorsSid, NULL, pSidAdmins, &cbSidAdmins );
  123. if ( !fRet )
  124. {
  125. dwError = GetLastError();
  126. hr = HRESULT_FROM_WIN32( dwError );
  127. goto exit;
  128. }
  129. DBG_ASSERT( pSidAdmins != NULL );
  130. // Setup AuthenticatedUsers for COM access.
  131. ea.grfAccessPermissions = COM_RIGHTS_EXECUTE;
  132. ea.grfAccessMode = SET_ACCESS;
  133. ea.grfInheritance = NO_INHERITANCE;
  134. ea.Trustee.pMultipleTrustee = NULL;
  135. ea.Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;
  136. ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
  137. ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
  138. ea.Trustee.ptstrName = (LPSTR)pSidAdmins;
  139. // Create new ACL with this ACE.
  140. dwError = SetEntriesInAcl( 1, &ea, NULL, &pAcl );
  141. if ( dwError != ERROR_SUCCESS )
  142. {
  143. hr = HRESULT_FROM_WIN32( dwError );
  144. goto exit;
  145. }
  146. DBG_ASSERT( pAcl != NULL );
  147. // Set the security descriptor owner to Administrators
  148. fRet = SetSecurityDescriptorOwner( &SecurityDesc, pSidAdmins, FALSE);
  149. if ( !fRet )
  150. {
  151. dwError = GetLastError();
  152. hr = HRESULT_FROM_WIN32( dwError );
  153. goto exit;
  154. }
  155. // Set the security descriptor group to Administrators
  156. fRet = SetSecurityDescriptorGroup( &SecurityDesc, pSidAdmins, FALSE);
  157. if ( !fRet )
  158. {
  159. dwError = GetLastError();
  160. hr = HRESULT_FROM_WIN32( dwError );
  161. goto exit;
  162. }
  163. // Set the ACL to the security descriptor.
  164. fRet = SetSecurityDescriptorDacl( &SecurityDesc, TRUE, pAcl, FALSE );
  165. if ( !fRet )
  166. {
  167. dwError = GetLastError();
  168. hr = HRESULT_FROM_WIN32( dwError );
  169. goto exit;
  170. }
  171. // Get the size of the self relative copy
  172. fRet = MakeSelfRelativeSD( &SecurityDesc, NULL, &cbSelfRelative );
  173. DBG_ASSERT( !fRet );
  174. // Allocate memory for the self relative security descriptor
  175. pSelfRelative = (SECURITY_DESCRIPTOR*)LocalAlloc( LPTR, cbSelfRelative );
  176. if ( pSelfRelative == NULL )
  177. {
  178. hr = E_OUTOFMEMORY;
  179. goto exit;
  180. }
  181. // Create a self relative copy, which we can store in the registry
  182. fRet = MakeSelfRelativeSD( &SecurityDesc, pSelfRelative, &cbSelfRelative );
  183. if ( !fRet )
  184. {
  185. dwError = GetLastError();
  186. hr = HRESULT_FROM_WIN32( dwError );
  187. goto exit;
  188. }
  189. // Write the security descriptor
  190. dwError = RegSetValueEx( hKey,
  191. "LaunchPermission",
  192. 0,
  193. REG_BINARY,
  194. (BYTE*)pSelfRelative,
  195. cbSelfRelative );
  196. if ( dwError != ERROR_SUCCESS )
  197. {
  198. hr = HRESULT_FROM_WIN32( dwError );
  199. goto exit;
  200. }
  201. exit:
  202. if ( pSelfRelative != NULL )
  203. {
  204. LocalFree( pSelfRelative );
  205. pSelfRelative = NULL;
  206. }
  207. if ( pSidAdmins != NULL )
  208. {
  209. LocalFree( pSidAdmins );
  210. pSidAdmins = NULL;
  211. }
  212. if ( pAcl != NULL )
  213. {
  214. LocalFree( pAcl );
  215. pAcl = NULL;
  216. }
  217. return (hr);
  218. }
  219. STDAPI
  220. DllRegisterServer()
  221. {
  222. DWORD dwError;
  223. HKEY hKeyCLSID;
  224. HKEY hKeyIF;
  225. HKEY hKeyAppExe;
  226. HKEY hKeyAppID;
  227. DWORD dwDisposition;
  228. //
  229. // register AppExe
  230. //
  231. //
  232. // register inetinfo AppID
  233. //
  234. dwError = RegCreateKeyExA( HKEY_CLASSES_ROOT,
  235. "AppID\\inetinfo.exe",
  236. 0,
  237. "",
  238. REG_OPTION_NON_VOLATILE,
  239. KEY_ALL_ACCESS,
  240. NULL,
  241. &hKeyAppExe,
  242. &dwDisposition );
  243. if ( dwError != ERROR_SUCCESS )
  244. {
  245. return E_UNEXPECTED;
  246. }
  247. dwError = RegSetValueExA( hKeyAppExe,
  248. "AppID",
  249. 0,
  250. REG_SZ,
  251. (BYTE*)"{A9E69610-B80D-11D0-B9B9-00A0C922E750}",
  252. sizeof("{A9E69610-B80D-11D0-B9B9-00A0C922E750}") );
  253. if ( dwError != ERROR_SUCCESS )
  254. {
  255. RegCloseKey(hKeyAppExe);
  256. return E_UNEXPECTED;
  257. }
  258. RegCloseKey(hKeyAppExe);
  259. //
  260. // register AppID
  261. //
  262. dwError = RegCreateKeyExA( HKEY_CLASSES_ROOT,
  263. "AppID\\{A9E69610-B80D-11D0-B9B9-00A0C922E750}",
  264. 0,
  265. "",
  266. REG_OPTION_NON_VOLATILE,
  267. KEY_ALL_ACCESS,
  268. NULL,
  269. &hKeyAppID,
  270. &dwDisposition );
  271. if ( dwError != ERROR_SUCCESS )
  272. {
  273. return E_UNEXPECTED;
  274. }
  275. if ( FAILED( SetABOLaunchPermissions( hKeyAppID ) ) )
  276. {
  277. RegCloseKey(hKeyAppID);
  278. return E_UNEXPECTED;
  279. }
  280. dwError = RegSetValueExA( hKeyAppID,
  281. "",
  282. 0,
  283. REG_SZ,
  284. (BYTE*)"IIS Admin Service",
  285. sizeof("IIS Admin Service") );
  286. if ( dwError != ERROR_SUCCESS )
  287. {
  288. RegCloseKey(hKeyAppID);
  289. return E_UNEXPECTED;
  290. }
  291. dwError = RegSetValueExA( hKeyAppID,
  292. "LocalService",
  293. 0,
  294. REG_SZ,
  295. (BYTE*)"IISADMIN",
  296. sizeof("IISADMIN") );
  297. if ( dwError != ERROR_SUCCESS )
  298. {
  299. RegCloseKey(hKeyAppID);
  300. return E_UNEXPECTED;
  301. }
  302. RegCloseKey(hKeyAppID);
  303. //
  304. // register CLSID
  305. //
  306. dwError = RegCreateKeyExA( HKEY_CLASSES_ROOT,
  307. "CLSID\\{A9E69610-B80D-11D0-B9B9-00A0C922E750}",
  308. 0,
  309. "",
  310. REG_OPTION_NON_VOLATILE,
  311. KEY_ALL_ACCESS,
  312. NULL,
  313. &hKeyCLSID,
  314. &dwDisposition );
  315. if ( dwError != ERROR_SUCCESS )
  316. {
  317. return E_UNEXPECTED;
  318. }
  319. dwError = RegSetValueExA( hKeyCLSID,
  320. "",
  321. 0,
  322. REG_SZ,
  323. (BYTE*)"IIS Admin Service",
  324. sizeof("IIS Admin Servce") );
  325. if ( dwError != ERROR_SUCCESS )
  326. {
  327. RegCloseKey(hKeyCLSID);
  328. return E_UNEXPECTED;
  329. }
  330. dwError = RegSetValueExA( hKeyCLSID,
  331. "AppID",
  332. 0,
  333. REG_SZ,
  334. (BYTE*)"{A9E69610-B80D-11D0-B9B9-00A0C922E750}",
  335. sizeof("{A9E69610-B80D-11D0-B9B9-00A0C922E750}") );
  336. if ( dwError != ERROR_SUCCESS )
  337. {
  338. RegCloseKey(hKeyCLSID);
  339. return E_UNEXPECTED;
  340. }
  341. dwError = RegSetValueExA( hKeyCLSID,
  342. "LocalService",
  343. 0,
  344. REG_SZ,
  345. (BYTE*)"IISADMIN",
  346. sizeof("IISADMIN") );
  347. if ( dwError !=ERROR_SUCCESS )
  348. {
  349. RegCloseKey(hKeyCLSID);
  350. return E_UNEXPECTED;
  351. }
  352. RegCloseKey(hKeyCLSID);
  353. //
  354. // IISADMIN registry entries
  355. //
  356. dwError = RegCreateKeyExA( HKEY_LOCAL_MACHINE,
  357. IISADMIN_EXTENSIONS_REG_KEY,
  358. 0,
  359. "",
  360. REG_OPTION_NON_VOLATILE,
  361. KEY_ALL_ACCESS,
  362. NULL,
  363. &hKeyIF,
  364. &dwDisposition );
  365. if ( dwError != ERROR_SUCCESS )
  366. {
  367. return E_UNEXPECTED;
  368. }
  369. RegCloseKey(hKeyIF);
  370. return S_OK;
  371. }
  372. STDAPI
  373. DllUnregisterServer()
  374. {
  375. HRESULT hr = S_OK;
  376. //
  377. // Delete Crypto Keys
  378. //
  379. hr = IISCryptoInitialize();
  380. if (SUCCEEDED(hr))
  381. {
  382. IISCryptoDeleteContainerByName( DCOM_SERVER_CONTAINER,
  383. 0 );
  384. IISCryptoDeleteContainerByName( DCOM_SERVER_CONTAINER,
  385. CRYPT_MACHINE_KEYSET );
  386. IISCryptoDeleteContainerByName( DCOM_CLIENT_CONTAINER,
  387. 0 );
  388. IISCryptoDeleteContainerByName( DCOM_CLIENT_CONTAINER,
  389. CRYPT_MACHINE_KEYSET );
  390. IISCryptoTerminate();
  391. }
  392. //
  393. // register AppID
  394. //
  395. RegDeleteKeyA( HKEY_CLASSES_ROOT,
  396. "AppID\\inetinfo.exe" );
  397. RegDeleteKeyA( HKEY_CLASSES_ROOT,
  398. "AppID\\{88E4BA60-537B-11D0-9B8E-00A0C922E703}" );
  399. RegDeleteKeyA( HKEY_CLASSES_ROOT,
  400. "AppID\\{A9E69610-B80D-11D0-B9B9-00A0C922E750}" );
  401. //
  402. // register CLSID
  403. //
  404. RegDeleteKeyA( HKEY_CLASSES_ROOT,
  405. "CLSID\\{88E4BA60-537B-11D0-9B8E-00A0C922E703}" );
  406. RegDeleteKeyA( HKEY_CLASSES_ROOT,
  407. "CLSID\\{A9E69610-B80D-11D0-B9B9-00A0C922E750}" );
  408. //
  409. // IISADMIN registry entries
  410. //
  411. RegDeleteKeyA( HKEY_LOCAL_MACHINE,
  412. IISADMIN_EXTENSIONS_REG_KEY );
  413. return S_OK;
  414. }
  415. STDAPI
  416. DllCanUnloadNow()
  417. {
  418. return S_FALSE;
  419. }