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.

1009 lines
28 KiB

  1. #include "gptext.h"
  2. #include <initguid.h>
  3. #include <iadsp.h>
  4. extern "C"{
  5. #include "wlrsop.h"
  6. }
  7. #include "wirelessext.h"
  8. #include "SmartPtr.h"
  9. #include "wbemtime.h"
  10. #include <adsopenflags.h>
  11. #include <strsafe.h>
  12. #define GPEXT_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\{0ACDD40C-75AC-47ab-BAA0-BF6DE7E7FE63}")
  13. #define POLICY_PATH TEXT("Software\\Policies\\Microsoft\\Windows\\Wireless\\GPTWirelessPolicy")
  14. LPWSTR GetWirelessAttributes[] = {L"msieee80211-ID", L"cn", L"description"};
  15. HRESULT
  16. RegisterWireless(void)
  17. {
  18. HKEY hKey;
  19. LONG lResult;
  20. DWORD dwDisp, dwValue;
  21. TCHAR szBuffer[512];
  22. lResult = RegCreateKeyEx (
  23. HKEY_LOCAL_MACHINE,
  24. GPEXT_PATH,
  25. 0,
  26. NULL,
  27. REG_OPTION_NON_VOLATILE,
  28. KEY_WRITE,
  29. NULL,
  30. &hKey,
  31. &dwDisp
  32. );
  33. if (lResult != ERROR_SUCCESS)
  34. {
  35. return lResult;
  36. }
  37. LoadString (g_hInstance, IDS_WIRELESS_NAME, szBuffer, ARRAYSIZE(szBuffer));
  38. RegSetValueEx (
  39. hKey,
  40. NULL,
  41. 0,
  42. REG_SZ,
  43. (LPBYTE)szBuffer,
  44. (lstrlen(szBuffer) + 1) * sizeof(TCHAR)
  45. );
  46. RegSetValueEx (
  47. hKey,
  48. TEXT("ProcessGroupPolicyEx"),
  49. 0,
  50. REG_SZ,
  51. (LPBYTE)TEXT("ProcessWIRELESSPolicyEx"),
  52. (lstrlen(TEXT("ProcessWIRELESSPolicyEx")) + 1) * sizeof(TCHAR)
  53. );
  54. RegSetValueEx (
  55. hKey,
  56. TEXT("GenerateGroupPolicy"),
  57. 0,
  58. REG_SZ,
  59. (LPBYTE)TEXT("GenerateWIRELESSPolicy"),
  60. (lstrlen(TEXT("GenerateWIRELESSPolicy")) + 1) * sizeof(TCHAR)
  61. );
  62. szBuffer[0] = L'\0';
  63. (void) StringCchCopy(szBuffer, ARRAYSIZE(szBuffer), L"gptext.dll");
  64. RegSetValueEx (
  65. hKey,
  66. TEXT("DllName"),
  67. 0,
  68. REG_EXPAND_SZ,
  69. (LPBYTE)szBuffer,
  70. (lstrlen(szBuffer) + 1) * sizeof(TCHAR)
  71. );
  72. dwValue = 1;
  73. RegSetValueEx (
  74. hKey,
  75. TEXT("NoUserPolicy"),
  76. 0,
  77. REG_DWORD,
  78. (LPBYTE)&dwValue,
  79. sizeof(dwValue));
  80. RegSetValueEx (
  81. hKey,
  82. TEXT("NoGPOListChanges"),
  83. 0,
  84. REG_DWORD,
  85. (LPBYTE)&dwValue,
  86. sizeof(dwValue));
  87. RegCloseKey (hKey);
  88. return S_OK;
  89. }
  90. HRESULT
  91. UnregisterWireless(void)
  92. {
  93. DWORD dwError = 0;
  94. dwError = RegDeleteKey (HKEY_LOCAL_MACHINE, GPEXT_PATH);
  95. return HRESULT_FROM_WIN32(dwError);
  96. }
  97. DWORD
  98. ProcessWIRELESSPolicyEx(
  99. DWORD dwFlags, // GPO_INFO_FLAGS
  100. HANDLE hToken, // User or machine token
  101. HKEY hKeyRoot, // Root of registry
  102. PGROUP_POLICY_OBJECT pDeletedGPOList, // Linked list of deleted GPOs
  103. PGROUP_POLICY_OBJECT pChangedGPOList, // Linked list of changed GPOs
  104. ASYNCCOMPLETIONHANDLE pHandle, // For asynchronous completion
  105. BOOL *pbAbort, // If true, then abort GPO processing
  106. PFNSTATUSMESSAGECALLBACK pStatusCallback,// Callback function for displaying status messages
  107. IWbemServices *pWbemServices, // Pointer to namespace to log diagnostic mode data
  108. // Note, this will be NULL when Rsop logging is disabled
  109. HRESULT *pRsopStatus // RSOP Logging succeeded or not.
  110. )
  111. {
  112. // Call ProcessWIRELESSPolicy & get path -> polstore funcs
  113. LPWSTR pszWIRELESSPolicyPath = NULL;
  114. WCHAR szWIRELESSPolicyName[MAX_PATH]; //policy name
  115. WCHAR szWIRELESSPolicyDescription[512]; //policy descr
  116. WCHAR szWIRELESSPolicyID[512]; //policy descr
  117. HRESULT hr = S_OK;
  118. PGROUP_POLICY_OBJECT pGPO = NULL;
  119. GPO_INFO GPOInfo;
  120. //validate the args.
  121. if (!pRsopStatus) {
  122. return(E_INVALIDARG);
  123. }
  124. //
  125. // Call CoInitialize for all the COM work we're doing
  126. //
  127. hr = CoInitializeEx(NULL,0);
  128. if (FAILED(hr)) {
  129. goto error;
  130. }
  131. memset(szWIRELESSPolicyName, 0, sizeof(WCHAR)*MAX_PATH);
  132. memset(szWIRELESSPolicyDescription, 0, sizeof(WCHAR)*512);
  133. memset(szWIRELESSPolicyID, 0, sizeof(WCHAR)*512);
  134. // First process the Deleted GPO List. If there is a single
  135. // entry on the GPO list, just delete the entire list.
  136. // Example Rex->Cassius->Brutus. If the delete List has
  137. // Cassius to be deleted, then really, we shouldn't be deleting
  138. // our registry entry because we're interested in Brutus which
  139. // has not be deleted. But in our case, the pChangedGPOList will
  140. // have all the information, so Brutus gets written back in the
  141. // next stage.
  142. //
  143. if (pDeletedGPOList) {
  144. DeleteWirelessPolicyFromRegistry();
  145. //
  146. // Also Clear WMI store if no GPO's applied and logging enabled
  147. //
  148. if (!pChangedGPOList && pWbemServices) {
  149. hr = WirelessClearWMIStore(
  150. pWbemServices
  151. );
  152. if (FAILED(hr)) {
  153. goto error;
  154. }
  155. DebugMsg( (DM_WARNING, L"wirelessext::ProcessWIRELESSPolicyEx: WIRELESS WMI store cleared") );
  156. }
  157. }
  158. if(pChangedGPOList) {
  159. DWORD dwNumGPO = 0;
  160. for(pGPO = pChangedGPOList; pGPO; pGPO = pGPO->pNext) {
  161. dwNumGPO++;
  162. //
  163. // Write only the last, highest precedence policy to registry
  164. //
  165. if(pGPO->pNext == NULL) {
  166. hr = RetrieveWirelessPolicyFromDS(
  167. pGPO,
  168. &pszWIRELESSPolicyPath,
  169. szWIRELESSPolicyName,
  170. ARRAYSIZE(szWIRELESSPolicyName),
  171. szWIRELESSPolicyDescription,
  172. ARRAYSIZE(szWIRELESSPolicyDescription),
  173. szWIRELESSPolicyID,
  174. ARRAYSIZE(szWIRELESSPolicyID)
  175. );
  176. if (FAILED(hr)) {
  177. goto success; // WMI store still consistent
  178. }
  179. hr = WriteWirelessPolicyToRegistry(
  180. pszWIRELESSPolicyPath,
  181. szWIRELESSPolicyName,
  182. szWIRELESSPolicyDescription,
  183. szWIRELESSPolicyID
  184. );
  185. if (pszWIRELESSPolicyPath) {
  186. LocalFree(pszWIRELESSPolicyPath);
  187. pszWIRELESSPolicyPath = NULL;
  188. }
  189. if (FAILED(hr)) {
  190. goto success; // WMI store still consistent
  191. }
  192. }
  193. }
  194. DebugMsg( (DM_WARNING, L"wirelessext::ProcessWIRELESSPolicyEx: dwNumGPO: %d", dwNumGPO) );
  195. // Write WMI log if logging enabled
  196. if (pWbemServices) {
  197. DWORD dwPrecedence = dwNumGPO;
  198. for(pGPO = pChangedGPOList; pGPO; pGPO = pGPO->pNext) {
  199. hr = RetrieveWirelessPolicyFromDS(
  200. pGPO,
  201. &pszWIRELESSPolicyPath,
  202. szWIRELESSPolicyName,
  203. ARRAYSIZE(szWIRELESSPolicyName),
  204. szWIRELESSPolicyDescription,
  205. ARRAYSIZE(szWIRELESSPolicyDescription),
  206. szWIRELESSPolicyID,
  207. ARRAYSIZE(szWIRELESSPolicyID)
  208. );
  209. if (FAILED(hr)) {
  210. goto error;
  211. }
  212. LPWSTR pszWIRELESSPolicy = pszWIRELESSPolicyPath + wcslen(L"LDAP://");
  213. DebugMsg( (DM_WARNING, L"wirelessext::ProcessWIRELESSPolicyEx: pszWIRELESSPolicy: %s", pszWIRELESSPolicy) );
  214. (VOID) CreateWlstoreGPOInfo(
  215. pGPO,
  216. dwPrecedence--,
  217. dwNumGPO,
  218. &GPOInfo
  219. );
  220. hr = WirelessWriteDirectoryPolicyToWMI(
  221. 0, //pszMachineName
  222. pszWIRELESSPolicy,
  223. &GPOInfo,
  224. pWbemServices
  225. );
  226. (VOID) FreeWlstoreGPOInfo(&GPOInfo);
  227. if (pszWIRELESSPolicyPath) {
  228. LocalFree(pszWIRELESSPolicyPath);
  229. pszWIRELESSPolicyPath = NULL;
  230. }
  231. if (FAILED(hr)) {
  232. DebugMsg( (DM_WARNING, L"WIRELESSext::ProcessWIRELESSPolicyEx: WirelessWriteDirectoryPolicyToWMI failed: 0x%x", hr) );
  233. goto error;
  234. }
  235. }
  236. }
  237. }
  238. DebugMsg( (DM_WARNING, L"wirelessext::ProcessWIRELESSPolicyEx completed") );
  239. PingWirelessPolicyAgent();
  240. CoUninitialize();
  241. success:
  242. *pRsopStatus = S_OK;
  243. return(ERROR_SUCCESS);
  244. error:
  245. /* Cannot Result in a double delete becuase,
  246. whenever we free, we set the pszWirelessPolicyPath to NULL
  247. so that freeing happens only once
  248. */
  249. if (pszWIRELESSPolicyPath) {
  250. LocalFree(pszWIRELESSPolicyPath);
  251. pszWIRELESSPolicyPath = NULL;
  252. }
  253. *pRsopStatus = hr;
  254. return(ERROR_POLICY_OBJECT_NOT_FOUND);
  255. }
  256. DWORD
  257. GenerateWIRELESSPolicy(
  258. DWORD dwFlags,
  259. BOOL *pbAbort,
  260. WCHAR *pwszSite,
  261. PRSOP_TARGET pMachTarget,
  262. PRSOP_TARGET pUserTarget
  263. )
  264. {
  265. // Call ProcessWIRELESSPolicy & get path -> polstore funcs
  266. LPWSTR pszWIRELESSPolicyPath = NULL; // policy Path
  267. WCHAR szWIRELESSPolicyName[MAX_PATH]; //policy name
  268. WCHAR szWIRELESSPolicyDescription[512]; //policy descr
  269. WCHAR szWIRELESSPolicyID[512]; //policy descr
  270. HRESULT hr = S_OK;
  271. PGROUP_POLICY_OBJECT pGPO = NULL;
  272. GPO_INFO GPOInfo;
  273. //
  274. // Call CoInitialize for all the COM work we're doing
  275. //
  276. hr = CoInitializeEx(NULL,0);
  277. if (FAILED(hr)) {
  278. goto error;
  279. }
  280. memset(szWIRELESSPolicyName, 0, sizeof(WCHAR)*MAX_PATH);
  281. memset(szWIRELESSPolicyDescription, 0, sizeof(WCHAR)*512);
  282. memset(szWIRELESSPolicyID, 0, sizeof(WCHAR)*512);
  283. ////start
  284. PGROUP_POLICY_OBJECT pChangedGPOList = NULL;
  285. IWbemServices *pWbemServices;
  286. if(pMachTarget) {
  287. pChangedGPOList = pMachTarget->pGPOList;
  288. pWbemServices = pMachTarget->pWbemServices;
  289. }
  290. if(pUserTarget) {
  291. pChangedGPOList = pUserTarget->pGPOList;
  292. pWbemServices = pUserTarget->pWbemServices;
  293. }
  294. if(pChangedGPOList) {
  295. DWORD dwNumGPO = 0;
  296. for(pGPO = pChangedGPOList; pGPO; pGPO = pGPO->pNext) {
  297. dwNumGPO++;
  298. }
  299. DebugMsg( (DM_WARNING, L"wirelessext::GenerateWIRELESSPolicy: dwNumGPO: %d", dwNumGPO) );
  300. DWORD dwPrecedence = dwNumGPO;
  301. for(pGPO = pChangedGPOList; pGPO; pGPO = pGPO->pNext) {
  302. hr = RetrieveWirelessPolicyFromDS(
  303. pGPO,
  304. &pszWIRELESSPolicyPath,
  305. szWIRELESSPolicyName,
  306. ARRAYSIZE(szWIRELESSPolicyName),
  307. szWIRELESSPolicyDescription,
  308. ARRAYSIZE(szWIRELESSPolicyDescription),
  309. szWIRELESSPolicyID,
  310. ARRAYSIZE(szWIRELESSPolicyID)
  311. );
  312. if (FAILED(hr)) {
  313. goto error;
  314. }
  315. LPWSTR pszWIRELESSPolicy = pszWIRELESSPolicyPath + wcslen(L"LDAP://");
  316. DebugMsg( (DM_WARNING, L"wirelessext::GenerateWIRELESSPolicy: pszWIRELESSPolicy: %s", pszWIRELESSPolicy) );
  317. (VOID) CreateWlstoreGPOInfo(
  318. pGPO,
  319. dwPrecedence--,
  320. dwNumGPO,
  321. &GPOInfo
  322. );
  323. hr = WirelessWriteDirectoryPolicyToWMI(
  324. 0, //pszMachineName
  325. pszWIRELESSPolicy,
  326. &GPOInfo,
  327. pWbemServices
  328. );
  329. (VOID) FreeWlstoreGPOInfo(&GPOInfo);
  330. if (pszWIRELESSPolicyPath) {
  331. LocalFree(pszWIRELESSPolicyPath);
  332. pszWIRELESSPolicyPath = NULL;
  333. }
  334. if (FAILED(hr)) {
  335. DebugMsg( (DM_WARNING, L"wirelessext::GenerateWIRELESSPolicy: WirelessWriteDirectoryPolicyToWMI failed: 0x%x", hr) );
  336. goto error;
  337. }
  338. }
  339. }
  340. DebugMsg( (DM_WARNING, L"wirelessext::GenerateWIRELESSPolicy completed") );
  341. CoUninitialize();
  342. return(ERROR_SUCCESS);
  343. error:
  344. /* Cannot Result in a double delete becuase,
  345. whenever we free, we set the pszWirelessPolicyPath to NULL
  346. so that freeing happens only once
  347. */
  348. if (pszWIRELESSPolicyPath) {
  349. LocalFree(pszWIRELESSPolicyPath);
  350. pszWIRELESSPolicyPath = NULL;
  351. }
  352. return(ERROR_POLICY_OBJECT_NOT_FOUND);
  353. }
  354. HRESULT
  355. CreateWlstoreGPOInfo(
  356. PGROUP_POLICY_OBJECT pGPO,
  357. UINT32 uiPrecedence,
  358. UINT32 uiTotalGPOs,
  359. PGPO_INFO pGPOInfo
  360. )
  361. {
  362. XBStr xbstrCurrentTime;
  363. HRESULT hr;
  364. memset(pGPOInfo, 0, sizeof(GPO_INFO));
  365. pGPOInfo->uiPrecedence = uiPrecedence;
  366. pGPOInfo->uiTotalGPOs = uiTotalGPOs;
  367. pGPOInfo->bsGPOID = SysAllocString(
  368. StripPrefixWireless(pGPO->lpDSPath)
  369. );
  370. pGPOInfo->bsSOMID = SysAllocString(
  371. StripLinkPrefixWireless(pGPO->lpLink)
  372. );
  373. // (Failing safe above by ignoring mem alloc errors)
  374. hr = GetCurrentWbemTime(xbstrCurrentTime);
  375. if ( FAILED (hr) ) {
  376. pGPOInfo->bsCreationtime = 0;
  377. }
  378. else {
  379. pGPOInfo->bsCreationtime = xbstrCurrentTime.Acquire();
  380. }
  381. return S_OK;
  382. }
  383. HRESULT
  384. FreeWlstoreGPOInfo(
  385. PGPO_INFO pGPOInfo
  386. )
  387. {
  388. if (pGPOInfo && pGPOInfo->bsCreationtime) {
  389. SysFreeString(pGPOInfo->bsCreationtime);
  390. }
  391. if (pGPOInfo && pGPOInfo->bsGPOID) {
  392. SysFreeString(pGPOInfo->bsGPOID);
  393. }
  394. if (pGPOInfo && pGPOInfo->bsSOMID) {
  395. SysFreeString(pGPOInfo->bsSOMID);
  396. }
  397. return S_OK;
  398. }
  399. HRESULT
  400. CreateWirelessChildPath(
  401. LPWSTR pszParentPath,
  402. LPWSTR pszChildComponent,
  403. BSTR * ppszChildPath
  404. )
  405. {
  406. HRESULT hr = S_OK;
  407. IADsPathname *pPathname = NULL;
  408. hr = CoCreateInstance(
  409. CLSID_Pathname,
  410. NULL,
  411. CLSCTX_ALL,
  412. IID_IADsPathname,
  413. (void**)&pPathname
  414. );
  415. BAIL_ON_FAILURE(hr);
  416. hr = pPathname->Set(pszParentPath, ADS_SETTYPE_FULL);
  417. BAIL_ON_FAILURE(hr);
  418. hr = pPathname->AddLeafElement(pszChildComponent);
  419. BAIL_ON_FAILURE(hr);
  420. hr = pPathname->Retrieve(ADS_FORMAT_X500, ppszChildPath);
  421. BAIL_ON_FAILURE(hr);
  422. error:
  423. if (pPathname) {
  424. pPathname->Release();
  425. }
  426. return(hr);
  427. }
  428. HRESULT
  429. RetrieveWirelessPolicyFromDS(
  430. PGROUP_POLICY_OBJECT pGPOInfo,
  431. LPWSTR *ppszWirelessPolicyPath,
  432. LPWSTR pszWirelessPolicyName,
  433. DWORD dwWirelessPolicyNameLen,
  434. LPWSTR pszWirelessPolicyDescription,
  435. DWORD dwWirelessPolicyDescLen,
  436. LPWSTR pszWirelessPolicyID,
  437. DWORD dwWirelessPolicyIDLen
  438. )
  439. {
  440. LPWSTR pszMachinePath = NULL;
  441. BSTR pszMicrosoftPath = NULL;
  442. BSTR pszWindowsPath = NULL;
  443. BSTR pszWirelessPath = NULL;
  444. BSTR pszLocWirelessPolicy = NULL;
  445. IDirectoryObject * pDirectoryObject = NULL;
  446. IDirectoryObject * pWirelessObject = NULL;
  447. IDirectorySearch * pWirelessSearch = NULL;
  448. BOOL bFound = FALSE;
  449. ADS_SEARCH_HANDLE hSearch;
  450. ADS_SEARCH_COLUMN col;
  451. WCHAR pszLocName[MAX_PATH+10]; // We need to store only CN=, in additon to the name.
  452. LPWSTR pszWirelessPolicyPath = NULL;
  453. DWORD dwWirelessPolicyPathLen = 0;
  454. DWORD dwError = 0;
  455. LPWSTR pszOwnersReference = L"wifiOwnersReference";
  456. HRESULT hr = S_OK;
  457. PADS_ATTR_INFO pAttributeEntries = NULL;
  458. DWORD dwNumAttributesReturned = 0;
  459. DWORD i = 0;
  460. PADS_ATTR_INFO pAttributeEntry = NULL;
  461. pszMachinePath = pGPOInfo->lpDSPath;
  462. // Build the fully qualified ADsPath for my object
  463. hr = CreateWirelessChildPath(
  464. pszMachinePath,
  465. L"cn=Microsoft",
  466. &pszMicrosoftPath
  467. );
  468. BAIL_ON_FAILURE(hr);
  469. hr = CreateWirelessChildPath(
  470. pszMicrosoftPath,
  471. L"cn=Windows",
  472. &pszWindowsPath
  473. );
  474. BAIL_ON_FAILURE(hr);
  475. hr = CreateWirelessChildPath(
  476. pszWindowsPath,
  477. L"cn=Wireless",
  478. &pszWirelessPath
  479. );
  480. BAIL_ON_FAILURE(hr);
  481. hr = AdminToolsOpenObject(
  482. pszWirelessPath,
  483. NULL,
  484. NULL,
  485. ADS_SECURE_AUTHENTICATION,
  486. IID_IDirectorySearch,
  487. (void **)&pWirelessSearch
  488. );
  489. BAIL_ON_FAILURE(hr);
  490. hr = pWirelessSearch->ExecuteSearch(
  491. L"(&(objectClass=msieee80211-Policy))", GetWirelessAttributes, 3, &hSearch );
  492. if (!SUCCEEDED(hr)) {
  493. pWirelessSearch->CloseSearchHandle(hSearch);
  494. BAIL_ON_FAILURE(hr);
  495. }
  496. hr = pWirelessSearch->GetNextRow(hSearch);
  497. if (!SUCCEEDED(hr)) {
  498. pWirelessSearch->CloseSearchHandle(hSearch);
  499. BAIL_ON_FAILURE(hr);
  500. }
  501. hr = pWirelessSearch->GetColumn(hSearch, L"cn", &col);
  502. if (!SUCCEEDED(hr)) {
  503. pWirelessSearch->CloseSearchHandle(hSearch);
  504. BAIL_ON_FAILURE(hr);
  505. }
  506. if (col.dwADsType != ADSTYPE_CASE_IGNORE_STRING) {
  507. DebugMsg((DM_ASSERT, L"wirelessext::RetrievePolicyFromDS: cn NOT adstype_case_ignore_string"));
  508. pWirelessSearch->FreeColumn(&col);
  509. pWirelessSearch->CloseSearchHandle(hSearch);
  510. hr = E_ADS_BAD_PARAMETER;
  511. BAIL_ON_FAILURE(hr);
  512. }
  513. hr = StringCchCopy(pszWirelessPolicyName, dwWirelessPolicyNameLen, col.pADsValues->CaseIgnoreString);
  514. BAIL_ON_FAILURE(hr);
  515. pWirelessSearch->FreeColumn(&col);
  516. pWirelessSearch->CloseSearchHandle(hSearch);
  517. hr = StringCchCopy(pszLocName, ARRAYSIZE(pszLocName), L"\0");
  518. ASSERT(SUCCEEDED(hr));
  519. hr = StringCchCopy(pszLocName, ARRAYSIZE(pszLocName), L"CN=");
  520. ASSERT(SUCCEEDED(hr));
  521. hr = StringCchCat(pszLocName, ARRAYSIZE(pszLocName), pszWirelessPolicyName);
  522. BAIL_ON_FAILURE(hr);
  523. hr = CreateWirelessChildPath(
  524. pszWirelessPath,
  525. pszLocName,
  526. &pszLocWirelessPolicy
  527. );
  528. BAIL_ON_FAILURE(hr);
  529. hr = AdminToolsOpenObject(
  530. pszLocWirelessPolicy,
  531. NULL,
  532. NULL,
  533. ADS_SECURE_AUTHENTICATION,
  534. IID_IDirectoryObject,
  535. (void **)&pWirelessObject
  536. );
  537. BAIL_ON_FAILURE(hr);
  538. hr = pWirelessObject->GetObjectAttributes(
  539. GetWirelessAttributes,
  540. 3,
  541. &pAttributeEntries,
  542. &dwNumAttributesReturned
  543. );
  544. BAIL_ON_FAILURE(hr);
  545. if (dwNumAttributesReturned == 0) {
  546. hr = E_FAIL;
  547. BAIL_ON_FAILURE(hr);
  548. }
  549. //
  550. // Process the PathName
  551. //
  552. //
  553. // Process the ID
  554. //
  555. for (i = 0; i < dwNumAttributesReturned; i++) {
  556. pAttributeEntry = pAttributeEntries + i;
  557. if (!_wcsicmp(pAttributeEntry->pszAttrName, L"msieee80211-ID")) {
  558. hr = StringCchCopy(pszWirelessPolicyID, dwWirelessPolicyIDLen, pAttributeEntry->pADsValues->DNString);
  559. BAIL_ON_FAILURE(hr);
  560. bFound = TRUE;
  561. break;
  562. }
  563. }
  564. if (!bFound) {
  565. hr = E_FAIL;
  566. BAIL_ON_FAILURE(hr);
  567. }
  568. //
  569. // Process the description
  570. //
  571. hr = StringCchCopy(pszWirelessPolicyDescription, dwWirelessPolicyDescLen, L"\0");
  572. BAIL_ON_FAILURE(hr);
  573. for (i = 0; i < dwNumAttributesReturned; i++) {
  574. pAttributeEntry = pAttributeEntries + i;
  575. if (!_wcsicmp(pAttributeEntry->pszAttrName, L"description")) {
  576. hr = StringCchCopy(pszWirelessPolicyDescription, dwWirelessPolicyDescLen, pAttributeEntry->pADsValues->DNString);
  577. BAIL_ON_FAILURE(hr);
  578. break;
  579. }
  580. }
  581. dwWirelessPolicyPathLen = wcslen(pszLocWirelessPolicy);
  582. pszWirelessPolicyPath = (LPWSTR) LocalAlloc(
  583. LPTR,
  584. sizeof(WCHAR) * (dwWirelessPolicyPathLen+1)
  585. );
  586. if (!pszWirelessPolicyPath) {
  587. dwError = GetLastError();
  588. hr = HRESULT_FROM_WIN32(dwError);
  589. }
  590. BAIL_ON_FAILURE(hr);
  591. memset(pszWirelessPolicyPath, 0, sizeof(WCHAR) * (dwWirelessPolicyPathLen+1));
  592. hr = StringCchCopy(pszWirelessPolicyPath, dwWirelessPolicyPathLen+1, pszLocWirelessPolicy);
  593. BAIL_ON_FAILURE(hr);
  594. *ppszWirelessPolicyPath = pszWirelessPolicyPath;
  595. error:
  596. if (pszLocWirelessPolicy) {
  597. SysFreeString(pszLocWirelessPolicy);
  598. }
  599. if (pszWirelessPath) {
  600. SysFreeString(pszWirelessPath);
  601. }
  602. if (pszWindowsPath) {
  603. SysFreeString(pszWindowsPath);
  604. }
  605. if (pszMicrosoftPath) {
  606. SysFreeString(pszMicrosoftPath);
  607. }
  608. return(hr);
  609. }
  610. DWORD
  611. DeleteWirelessPolicyFromRegistry(
  612. )
  613. {
  614. DWORD dwError = 0;
  615. HKEY hKey = NULL;
  616. DWORD dwDisp = 0;
  617. dwError = RegCreateKeyEx (
  618. HKEY_LOCAL_MACHINE,
  619. TEXT("Software\\Policies\\Microsoft\\Windows\\Wireless"),
  620. 0,
  621. NULL,
  622. REG_OPTION_NON_VOLATILE,
  623. KEY_ALL_ACCESS,
  624. NULL,
  625. &hKey,
  626. &dwDisp
  627. );
  628. if (dwError) {
  629. goto error;
  630. }
  631. dwError = RegDeleteKey(
  632. hKey,
  633. L"GPTWirelessPolicy"
  634. );
  635. /*
  636. dwError = RegDeleteValue(
  637. hKey,
  638. TEXT("DSWIRELESSPolicyPath")
  639. );
  640. dwError = RegDeleteValue(
  641. hKey,
  642. TEXT("DSWIRELESSPolicyName")
  643. );*/
  644. error:
  645. if (hKey) {
  646. RegCloseKey (hKey);
  647. }
  648. return(dwError);
  649. }
  650. DWORD
  651. WriteWirelessPolicyToRegistry(
  652. LPWSTR pszWirelessPolicyPath,
  653. LPWSTR pszWirelessPolicyName,
  654. LPWSTR pszWirelessPolicyDescription,
  655. LPWSTR pszWirelessPolicyID
  656. )
  657. {
  658. DWORD dwError = 0;
  659. DWORD dwDisp = 0;
  660. HKEY hKey = NULL;
  661. DWORD dwFlags = 1;
  662. dwError = RegCreateKeyEx (
  663. HKEY_LOCAL_MACHINE,
  664. POLICY_PATH,
  665. 0,
  666. NULL,
  667. REG_OPTION_NON_VOLATILE,
  668. KEY_ALL_ACCESS,
  669. NULL,
  670. &hKey,
  671. &dwDisp
  672. );
  673. if (dwError) {
  674. goto error;
  675. }
  676. if (pszWirelessPolicyPath && *pszWirelessPolicyPath) {
  677. dwError = RegSetValueEx (
  678. hKey,
  679. TEXT("DSWirelessPolicyPath"),
  680. 0,
  681. REG_SZ,
  682. (LPBYTE)pszWirelessPolicyPath,
  683. (lstrlen(pszWirelessPolicyPath) + 1) * sizeof(TCHAR)
  684. );
  685. dwFlags = 1;
  686. dwError = RegSetValueEx (
  687. hKey,
  688. TEXT("DSWirelessPolicyFlags"),
  689. 0,
  690. REG_DWORD,
  691. (LPBYTE)&dwFlags,
  692. sizeof(dwFlags)
  693. );
  694. }
  695. if (pszWirelessPolicyName && *pszWirelessPolicyName) {
  696. dwError = RegSetValueEx (
  697. hKey,
  698. TEXT("DSWirelessPolicyName"),
  699. 0,
  700. REG_SZ,
  701. (LPBYTE)pszWirelessPolicyName,
  702. (lstrlen(pszWirelessPolicyName) + 1) * sizeof(TCHAR)
  703. );
  704. }
  705. if (pszWirelessPolicyID && *pszWirelessPolicyID) {
  706. dwError = RegSetValueEx (
  707. hKey,
  708. TEXT("WirelessID"),
  709. 0,
  710. REG_SZ,
  711. (LPBYTE)pszWirelessPolicyID,
  712. (lstrlen(pszWirelessPolicyID) + 1) * sizeof(TCHAR)
  713. );
  714. }
  715. if (pszWirelessPolicyDescription && *pszWirelessPolicyDescription) {
  716. dwError = RegSetValueEx (
  717. hKey,
  718. TEXT("DSWirelessPolicyDescription"),
  719. 0,
  720. REG_SZ,
  721. (LPBYTE)pszWirelessPolicyDescription,
  722. (lstrlen(pszWirelessPolicyDescription) + 1) * sizeof(TCHAR)
  723. );
  724. }
  725. error:
  726. if (hKey) {
  727. RegCloseKey (hKey);
  728. }
  729. return(dwError);
  730. }
  731. VOID
  732. PingWirelessPolicyAgent(
  733. )
  734. {
  735. HANDLE hPolicyChangeEvent = NULL;
  736. hPolicyChangeEvent = OpenEvent(
  737. EVENT_ALL_ACCESS,
  738. FALSE,
  739. L"WIRELESS_POLICY_CHANGE_EVENT"
  740. );
  741. if (hPolicyChangeEvent) {
  742. SetEvent(hPolicyChangeEvent);
  743. CloseHandle(hPolicyChangeEvent);
  744. }
  745. }
  746. //
  747. // Prefix stripping functions copied from
  748. // gina\userenv\rsop\logger.cpp written by SitaramR
  749. //
  750. //*************************************************************
  751. //
  752. // StripPrefix()
  753. //
  754. // Purpose: Strips out prefix to get canonical path to Gpo
  755. //
  756. // Parameters: lpGPOInfo - Gpo Info
  757. // pWbemServices - Wbem services
  758. //
  759. // Returns: Pointer to suffix
  760. //
  761. //*************************************************************
  762. WCHAR *StripPrefixWireless( WCHAR *pwszPath )
  763. {
  764. WCHAR wszMachPrefix[] = TEXT("LDAP://CN=Machine,");
  765. INT iMachPrefixLen = lstrlen( wszMachPrefix );
  766. WCHAR wszUserPrefix[] = TEXT("LDAP://CN=User,");
  767. INT iUserPrefixLen = lstrlen( wszUserPrefix );
  768. WCHAR *pwszPathSuffix;
  769. //
  770. // Strip out prefix to get the canonical path to Gpo
  771. //
  772. if ( CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE,
  773. pwszPath, iUserPrefixLen, wszUserPrefix, iUserPrefixLen ) == CSTR_EQUAL ) {
  774. pwszPathSuffix = pwszPath + iUserPrefixLen;
  775. } else if ( CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE,
  776. pwszPath, iMachPrefixLen, wszMachPrefix, iMachPrefixLen ) == CSTR_EQUAL ) {
  777. pwszPathSuffix = pwszPath + iMachPrefixLen;
  778. } else
  779. pwszPathSuffix = pwszPath;
  780. return pwszPathSuffix;
  781. }
  782. //*************************************************************
  783. //
  784. // StripLinkPrefix()
  785. //
  786. // Purpose: Strips out prefix to get canonical path to DS
  787. // object
  788. //
  789. // Parameters: pwszPath - path to strip
  790. //
  791. // Returns: Pointer to suffix
  792. //
  793. //*************************************************************
  794. WCHAR *StripLinkPrefixWireless( WCHAR *pwszPath )
  795. {
  796. WCHAR wszPrefix[] = TEXT("LDAP://");
  797. INT iPrefixLen = lstrlen( wszPrefix );
  798. WCHAR *pwszPathSuffix;
  799. //
  800. // Strip out prefix to get the canonical path to Som
  801. //
  802. if ( wcslen(pwszPath) <= (DWORD) iPrefixLen ) {
  803. return pwszPath;
  804. }
  805. if ( CompareString( LOCALE_USER_DEFAULT, NORM_IGNORECASE,
  806. pwszPath, iPrefixLen, wszPrefix, iPrefixLen ) == CSTR_EQUAL ) {
  807. pwszPathSuffix = pwszPath + iPrefixLen;
  808. } else
  809. pwszPathSuffix = pwszPath;
  810. return pwszPathSuffix;
  811. }