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.

1261 lines
31 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. scemm.cpp
  5. Abstract:
  6. Shared memory management APIs
  7. Author:
  8. Jin Huang
  9. Revision History:
  10. jinhuang 23-Jan-1998 merged from multiple modules
  11. --*/
  12. #include "headers.h"
  13. #include "scesvc.h"
  14. PVOID
  15. MIDL_user_allocate (
  16. size_t NumBytes
  17. )
  18. /*++
  19. Routine Description:
  20. Allocates storage for RPC server transactions. The RPC stubs will
  21. either call MIDL_user_allocate when it needs to un-marshall data into a
  22. buffer that the user must free. RPC servers will use MIDL_user_allocate to
  23. allocate storage that the RPC server stub will free after marshalling
  24. the data.
  25. Arguments:
  26. NumBytes - The number of bytes to allocate.
  27. Return Value:
  28. none
  29. Note:
  30. --*/
  31. {
  32. PVOID Buffer = (PVOID) ScepAlloc(LMEM_FIXED,(DWORD)NumBytes);
  33. if (Buffer != NULL) {
  34. RtlZeroMemory( Buffer, NumBytes );
  35. }
  36. return( Buffer );
  37. }
  38. VOID
  39. MIDL_user_free (
  40. void *MemPointer
  41. )
  42. /*++
  43. Routine Description:
  44. Frees storage used in RPC transactions. The RPC client can call this
  45. function to free buffer space that was allocated by the RPC client
  46. stub when un-marshalling data that is to be returned to the client.
  47. The Client calls MIDL_user_free when it is finished with the data and
  48. desires to free up the storage.
  49. The RPC server stub calls MIDL_user_free when it has completed
  50. marshalling server data that is to be passed back to the client.
  51. Arguments:
  52. MemPointer - This points to the memory block that is to be released.
  53. Return Value:
  54. none.
  55. Note:
  56. --*/
  57. {
  58. ScepFree(MemPointer);
  59. }
  60. SCESTATUS
  61. ScepFreeNameList(
  62. IN PSCE_NAME_LIST pName
  63. )
  64. /* ++
  65. Routine Description:
  66. This routine frees memory associated with PSCE_NAME_LIST pName
  67. Arguments:
  68. pName - a NAME_LIST
  69. Return value:
  70. SCESTATUS_SUCCESS
  71. -- */
  72. {
  73. PSCE_NAME_LIST pCurName;
  74. PSCE_NAME_LIST pTempName;
  75. SCESTATUS rc=SCESTATUS_SUCCESS;
  76. if ( pName == NULL )
  77. return(rc);
  78. //
  79. // free the Name component first then free the node
  80. //
  81. pCurName = pName;
  82. while ( pCurName != NULL ) {
  83. if ( pCurName->Name != NULL )
  84. __try {
  85. ScepFree( pCurName->Name );
  86. } __except (EXCEPTION_EXECUTE_HANDLER) {
  87. rc = SCESTATUS_INVALID_PARAMETER;
  88. }
  89. pTempName = pCurName;
  90. pCurName = pCurName->Next;
  91. __try {
  92. ScepFree( pTempName );
  93. } __except (EXCEPTION_EXECUTE_HANDLER) {
  94. rc = SCESTATUS_INVALID_PARAMETER;
  95. }
  96. }
  97. return(rc);
  98. }
  99. HLOCAL
  100. ScepAlloc(
  101. IN UINT uFlags,
  102. IN UINT uBytes
  103. )
  104. /*
  105. memory allocation routine, which calls LocalAlloc.
  106. */
  107. {
  108. HLOCAL pTemp=NULL;
  109. pTemp = LocalAlloc(uFlags, uBytes);
  110. #ifdef SCE_DBG
  111. if ( pTemp != NULL ) {
  112. TotalBytes += uBytes;
  113. printf("Allocate %d bytes at 0x%x. Total bytes = %d\n", uBytes, pTemp, TotalBytes);
  114. }
  115. #endif
  116. return(pTemp);
  117. }
  118. VOID
  119. ScepFree(
  120. HLOCAL pToFree
  121. )
  122. /*
  123. memory free routine, which calls LocalFree.
  124. */
  125. { HLOCAL pTemp;
  126. if (pToFree != NULL) {
  127. pTemp = LocalFree( pToFree );
  128. #ifdef SCE_DBG
  129. if ( pTemp == NULL )
  130. printf("0x%x is freed\n", pToFree);
  131. else
  132. printf("Unable to free 0x%x. Error code=%d\n", pToFree, GetLastError());
  133. #endif
  134. }
  135. }
  136. SCESTATUS
  137. ScepFreeErrorLog(
  138. IN PSCE_ERROR_LOG_INFO Errlog
  139. )
  140. /* ++
  141. Routine Description:
  142. This routine frees memory associated with SCE_ERROR_LOG_INFO list
  143. Arguments
  144. Errlog - Head of the error log
  145. Return value:
  146. SCESTATUS
  147. -- */
  148. {
  149. PSCE_ERROR_LOG_INFO pErr;
  150. PSCE_ERROR_LOG_INFO pTemp;
  151. if ( Errlog != NULL ) {
  152. pErr = Errlog;
  153. while ( pErr != NULL ) {
  154. if ( pErr->buffer != NULL )
  155. ScepFree( pErr->buffer );
  156. pTemp = pErr;
  157. pErr = pErr->next;
  158. ScepFree( pTemp );
  159. }
  160. }
  161. return(SCESTATUS_SUCCESS);
  162. }
  163. SCESTATUS
  164. ScepFreeRegistryValues(
  165. IN PSCE_REGISTRY_VALUE_INFO *ppRegValues,
  166. IN DWORD Count
  167. )
  168. /*
  169. free memory allocated for the array of SCE_REGISTRY_VALUE_INFO
  170. */
  171. {
  172. if ( ppRegValues && *ppRegValues ) {
  173. for ( DWORD i=0; i<Count; i++ ) {
  174. //
  175. // free value name buffer within each element
  176. //
  177. if ( (*ppRegValues)[i].FullValueName ) {
  178. ScepFree((*ppRegValues)[i].FullValueName);
  179. }
  180. __try {
  181. if ( (*ppRegValues)[i].Value ) {
  182. //
  183. // this is a pointer of PWSTR
  184. //
  185. ScepFree((*ppRegValues)[i].Value);
  186. }
  187. } __except (EXCEPTION_EXECUTE_HANDLER) {
  188. }
  189. }
  190. //
  191. // free the array buffer
  192. //
  193. ScepFree(*ppRegValues);
  194. *ppRegValues = NULL;
  195. }
  196. return(SCESTATUS_SUCCESS);
  197. }
  198. SCESTATUS
  199. WINAPI
  200. SceFreeMemory(
  201. IN PVOID sceInfo,
  202. IN DWORD Category
  203. )
  204. /* ++
  205. Routine Description:
  206. This routine frees memory associated with SceInfo in the specified area.
  207. The Type field in SceInfo indicates the type of the structure.
  208. Arguments:
  209. SceInfo - The memory buffer to free. It could be type
  210. SCE_ENGINE_SCP
  211. SCE_ENGINE_SAP
  212. SCE_ENGINE_SMP
  213. SCE_STRUCT_PROFILE
  214. SCE_STRUCT_USER
  215. Area - The security area to free. This argument is only used for
  216. SCE_ENGINE_SCP, SCE_ENGINE_SAP, and SCE_ENGINE_SMP types.
  217. Return value:
  218. None
  219. -- */
  220. {
  221. SCETYPE sceType;
  222. AREA_INFORMATION Area;
  223. PSCE_PROFILE_INFO pProfileInfo=NULL;
  224. PSCE_USER_PROFILE pProfile;
  225. PSCE_LOGON_HOUR pTempLogon;
  226. PSCE_USER_SETTING pPerUser;
  227. PSCE_OBJECT_SECURITY pos;
  228. SCESTATUS rc=SCESTATUS_SUCCESS;
  229. if ( sceInfo == NULL )
  230. return(SCESTATUS_SUCCESS);
  231. if ( Category >= 300 ) {
  232. //
  233. // memory associated with list
  234. //
  235. __try {
  236. switch ( Category ) {
  237. case SCE_STRUCT_NAME_LIST:
  238. ScepFreeNameList((PSCE_NAME_LIST)sceInfo);
  239. break;
  240. case SCE_STRUCT_NAME_STATUS_LIST:
  241. ScepFreeNameStatusList( (PSCE_NAME_STATUS_LIST)sceInfo );
  242. break;
  243. case SCE_STRUCT_PRIVILEGE_VALUE_LIST:
  244. ScepFreePrivilegeValueList( (PSCE_PRIVILEGE_VALUE_LIST)sceInfo );
  245. break;
  246. case SCE_STRUCT_PRIVILEGE:
  247. ScepFreePrivilege( (PSCE_PRIVILEGE_ASSIGNMENT)sceInfo );
  248. break;
  249. case SCE_STRUCT_GROUP:
  250. ScepFreeGroupMembership( (PSCE_GROUP_MEMBERSHIP)sceInfo );
  251. break;
  252. case SCE_STRUCT_OBJECT_LIST:
  253. ScepFreeObjectList( (PSCE_OBJECT_LIST)sceInfo );
  254. break;
  255. case SCE_STRUCT_OBJECT_CHILDREN:
  256. ScepFreeObjectChildren( (PSCE_OBJECT_CHILDREN)sceInfo );
  257. break;
  258. case SCE_STRUCT_OBJECT_SECURITY:
  259. pos = (PSCE_OBJECT_SECURITY)sceInfo;
  260. if ( pos ) {
  261. if ( pos->Name != NULL )
  262. ScepFree( pos->Name );
  263. if ( pos->pSecurityDescriptor != NULL )
  264. ScepFree(pos->pSecurityDescriptor);
  265. ScepFree( pos );
  266. }
  267. break;
  268. case SCE_STRUCT_OBJECT_ARRAY:
  269. ScepFreeObjectSecurity( (PSCE_OBJECT_ARRAY)sceInfo );
  270. break;
  271. case SCE_STRUCT_PROFILE:
  272. case SCE_STRUCT_USER:
  273. SceFreeMemory( sceInfo, 0 ); // type is embedded
  274. break;
  275. case SCE_STRUCT_ERROR_LOG_INFO:
  276. ScepFreeErrorLog( (PSCE_ERROR_LOG_INFO)sceInfo );
  277. break;
  278. case SCE_STRUCT_SERVICES:
  279. SceFreePSCE_SERVICES((PSCE_SERVICES)sceInfo);
  280. break;
  281. default:
  282. rc = SCESTATUS_INVALID_PARAMETER;
  283. }
  284. } __except (EXCEPTION_EXECUTE_HANDLER) {
  285. ASSERT(FALSE);
  286. rc = SCESTATUS_INVALID_PARAMETER;
  287. }
  288. } else {
  289. sceType = *((SCETYPE *)sceInfo);
  290. Area = (AREA_INFORMATION)Category;
  291. switch ( sceType ) {
  292. case SCE_ENGINE_SCP:
  293. case SCE_ENGINE_SAP:
  294. case SCE_ENGINE_SMP:
  295. case SCE_ENGINE_SCP_INTERNAL:
  296. case SCE_ENGINE_SMP_INTERNAL:
  297. case SCE_STRUCT_INF:
  298. pProfileInfo = (PSCE_PROFILE_INFO)sceInfo;
  299. #if 0
  300. if ( Area & AREA_DS_OBJECTS ) {
  301. //
  302. // free ds list
  303. //
  304. if ( sceType == SCE_STRUCT_INF ) {
  305. ScepFreeObjectSecurity(pProfileInfo->pDsObjects.pAllNodes);
  306. pProfileInfo->pDsObjects.pAllNodes = NULL;
  307. } else {
  308. ScepFreeObjectList(pProfileInfo->pDsObjects.pOneLevel);
  309. pProfileInfo->pDsObjects.pOneLevel = NULL;
  310. }
  311. }
  312. #endif
  313. if ( Area & AREA_FILE_SECURITY ) {
  314. //
  315. // free file list and auditing list
  316. //
  317. __try {
  318. if ( sceType == SCE_STRUCT_INF ) {
  319. ScepFreeObjectSecurity(pProfileInfo->pFiles.pAllNodes);
  320. pProfileInfo->pFiles.pAllNodes = NULL;
  321. } else {
  322. ScepFreeObjectList(pProfileInfo->pFiles.pOneLevel);
  323. pProfileInfo->pFiles.pOneLevel = NULL;
  324. }
  325. } __except (EXCEPTION_EXECUTE_HANDLER) {
  326. ASSERT(FALSE);
  327. rc = SCESTATUS_INVALID_PARAMETER;
  328. }
  329. }
  330. if ( Area & AREA_REGISTRY_SECURITY ) {
  331. //
  332. // free registry keys list and auditing list
  333. //
  334. __try {
  335. if ( sceType == SCE_STRUCT_INF ) {
  336. ScepFreeObjectSecurity(pProfileInfo->pRegistryKeys.pAllNodes);
  337. pProfileInfo->pRegistryKeys.pAllNodes = NULL;
  338. } else {
  339. ScepFreeObjectList(pProfileInfo->pRegistryKeys.pOneLevel);
  340. pProfileInfo->pRegistryKeys.pOneLevel = NULL;
  341. }
  342. } __except (EXCEPTION_EXECUTE_HANDLER) {
  343. ASSERT(FALSE);
  344. rc = SCESTATUS_INVALID_PARAMETER;
  345. }
  346. }
  347. if ( Area & AREA_GROUP_MEMBERSHIP ) {
  348. __try {
  349. ScepFreeGroupMembership(pProfileInfo->pGroupMembership);
  350. pProfileInfo->pGroupMembership = NULL;
  351. } __except (EXCEPTION_EXECUTE_HANDLER) {
  352. ASSERT(FALSE);
  353. rc = SCESTATUS_INVALID_PARAMETER;
  354. }
  355. }
  356. if ( Area & AREA_PRIVILEGES ) {
  357. __try {
  358. switch ( sceType ) {
  359. case SCE_ENGINE_SCP_INTERNAL:
  360. case SCE_ENGINE_SMP_INTERNAL:
  361. //
  362. // SCP type Privilege Rights
  363. //
  364. ScepFreePrivilegeValueList(pProfileInfo->OtherInfo.scp.u.pPrivilegeAssignedTo);
  365. pProfileInfo->OtherInfo.scp.u.pPrivilegeAssignedTo = NULL;
  366. break;
  367. case SCE_STRUCT_INF:
  368. ScepFreePrivilege(pProfileInfo->OtherInfo.scp.u.pInfPrivilegeAssignedTo);
  369. pProfileInfo->OtherInfo.scp.u.pInfPrivilegeAssignedTo = NULL;
  370. break;
  371. case SCE_ENGINE_SMP:
  372. case SCE_ENGINE_SCP:
  373. //
  374. // SMP type Privilege Rights
  375. //
  376. ScepFreePrivilege(pProfileInfo->OtherInfo.smp.pPrivilegeAssignedTo);
  377. pProfileInfo->OtherInfo.smp.pPrivilegeAssignedTo = NULL;
  378. break;
  379. default: // SAP
  380. ScepFreePrivilege(pProfileInfo->OtherInfo.sap.pPrivilegeAssignedTo);
  381. pProfileInfo->OtherInfo.sap.pPrivilegeAssignedTo=NULL;
  382. break;
  383. }
  384. } __except (EXCEPTION_EXECUTE_HANDLER) {
  385. ASSERT(FALSE);
  386. rc = SCESTATUS_INVALID_PARAMETER;
  387. }
  388. }
  389. if ( Area & AREA_USER_SETTINGS ) {
  390. __try {
  391. switch ( sceType ) {
  392. case SCE_ENGINE_SCP_INTERNAL:
  393. case SCE_ENGINE_SMP_INTERNAL:
  394. case SCE_STRUCT_INF:
  395. //
  396. // Account Profiles
  397. //
  398. ScepFreeNameList(pProfileInfo->OtherInfo.scp.pAccountProfiles);
  399. pProfileInfo->OtherInfo.scp.pAccountProfiles = NULL;
  400. break;
  401. case SCE_ENGINE_SAP:
  402. //
  403. // SAP type
  404. //
  405. ScepFreeNameList(pProfileInfo->OtherInfo.sap.pUserList);
  406. pProfileInfo->OtherInfo.sap.pUserList = NULL;
  407. break;
  408. default: // SMP or SCP
  409. ScepFreeNameList(pProfileInfo->OtherInfo.smp.pUserList);
  410. pProfileInfo->OtherInfo.smp.pUserList = NULL;
  411. break;
  412. }
  413. } __except (EXCEPTION_EXECUTE_HANDLER) {
  414. ASSERT(FALSE);
  415. rc = SCESTATUS_INVALID_PARAMETER;
  416. }
  417. }
  418. if ( Area & AREA_SECURITY_POLICY ) {
  419. __try {
  420. if (pProfileInfo->NewAdministratorName != NULL ) {
  421. ScepFree( pProfileInfo->NewAdministratorName );
  422. pProfileInfo->NewAdministratorName = NULL;
  423. }
  424. if (pProfileInfo->NewGuestName != NULL ) {
  425. ScepFree( pProfileInfo->NewGuestName );
  426. pProfileInfo->NewGuestName = NULL;
  427. }
  428. if ( pProfileInfo->pKerberosInfo ) {
  429. ScepFree(pProfileInfo->pKerberosInfo);
  430. pProfileInfo->pKerberosInfo = NULL;
  431. }
  432. if ( pProfileInfo->RegValueCount && pProfileInfo->aRegValues ) {
  433. ScepFreeRegistryValues(&pProfileInfo->aRegValues,
  434. pProfileInfo->RegValueCount);
  435. }
  436. pProfileInfo->RegValueCount = 0;
  437. pProfileInfo->aRegValues = NULL;
  438. ScepResetSecurityPolicyArea(pProfileInfo);
  439. } __except (EXCEPTION_EXECUTE_HANDLER) {
  440. ASSERT(FALSE);
  441. rc = SCESTATUS_INVALID_PARAMETER;
  442. }
  443. }
  444. break;
  445. case SCE_STRUCT_PROFILE:
  446. pProfile = (PSCE_USER_PROFILE)sceInfo;
  447. if ( pProfile != NULL ) {
  448. __try {
  449. if (pProfile->UserProfile != NULL )
  450. ScepFree(pProfile->UserProfile);
  451. pProfile->UserProfile = NULL;
  452. if (pProfile->LogonScript != NULL )
  453. ScepFree(pProfile->LogonScript);
  454. pProfile->LogonScript = NULL;
  455. if (pProfile->HomeDir != NULL )
  456. ScepFree(pProfile->HomeDir);
  457. pProfile->HomeDir = NULL;
  458. //
  459. // Logon hours
  460. //
  461. while (pProfile->pLogonHours != NULL ) {
  462. pTempLogon = pProfile->pLogonHours;
  463. pProfile->pLogonHours = pProfile->pLogonHours->Next;
  464. ScepFree(pTempLogon);
  465. }
  466. pProfile->pLogonHours = NULL;
  467. //
  468. // free Workstation name list
  469. //
  470. if ( pProfile->pWorkstations.Buffer != NULL )
  471. ScepFree(pProfile->pWorkstations.Buffer);
  472. pProfile->pWorkstations.Buffer = NULL;
  473. pProfile->pWorkstations.MaximumLength = 0;
  474. pProfile->pWorkstations.Length = 0;
  475. //
  476. // free Groups name list
  477. //
  478. ScepFreeNameList(pProfile->pGroupsBelongsTo);
  479. pProfile->pGroupsBelongsTo = NULL;
  480. //
  481. // free AssignToUsers name list
  482. //
  483. ScepFreeNameList(pProfile->pAssignToUsers);
  484. pProfile->pAssignToUsers = NULL;
  485. //
  486. // free SDs
  487. //
  488. if (pProfile->pHomeDirSecurity != NULL )
  489. ScepFree(pProfile->pHomeDirSecurity);
  490. pProfile->pHomeDirSecurity = NULL;
  491. if (pProfile->pTempDirSecurity != NULL )
  492. ScepFree(pProfile->pTempDirSecurity);
  493. pProfile->pTempDirSecurity = NULL;
  494. ScepFree(pProfile);
  495. } __except (EXCEPTION_EXECUTE_HANDLER) {
  496. ASSERT(FALSE);
  497. rc = SCESTATUS_INVALID_PARAMETER;
  498. }
  499. }
  500. break;
  501. case SCE_STRUCT_USER:
  502. pPerUser = (PSCE_USER_SETTING)sceInfo;
  503. if ( pPerUser != NULL ) {
  504. __try {
  505. ScepFreeNameList( pPerUser->pGroupsBelongsTo);
  506. pPerUser->pGroupsBelongsTo = NULL;
  507. if (pPerUser->UserProfile != NULL)
  508. ScepFree(pPerUser->UserProfile);
  509. pPerUser->UserProfile = NULL;
  510. if (pPerUser->pProfileSecurity != NULL)
  511. ScepFree(pPerUser->pProfileSecurity);
  512. pPerUser->pProfileSecurity = NULL;
  513. if (pPerUser->LogonScript != NULL)
  514. ScepFree(pPerUser->LogonScript);
  515. pPerUser->LogonScript = NULL;
  516. if (pPerUser->pLogonScriptSecurity != NULL)
  517. ScepFree(pPerUser->pLogonScriptSecurity);
  518. pPerUser->pLogonScriptSecurity = NULL;
  519. if (pPerUser->HomeDir != NULL)
  520. ScepFree(pPerUser->HomeDir);
  521. pPerUser->HomeDir = NULL;
  522. if (pPerUser->pHomeDirSecurity != NULL)
  523. ScepFree(pPerUser->pHomeDirSecurity);
  524. pPerUser->pHomeDirSecurity = NULL;
  525. if (pPerUser->TempDir != NULL)
  526. ScepFree(pPerUser->TempDir);
  527. pPerUser->TempDir = NULL;
  528. if (pPerUser->pTempDirSecurity != NULL)
  529. ScepFree(pPerUser->pTempDirSecurity);
  530. pPerUser->pTempDirSecurity = NULL;
  531. while (pPerUser->pLogonHours != NULL ) {
  532. pTempLogon = pPerUser->pLogonHours;
  533. pPerUser->pLogonHours = pPerUser->pLogonHours->Next;
  534. ScepFree(pTempLogon);
  535. }
  536. pPerUser->pLogonHours = NULL;
  537. if ( pPerUser->pWorkstations.Buffer != NULL )
  538. ScepFree( pPerUser->pWorkstations.Buffer );
  539. pPerUser->pWorkstations.Buffer = NULL;
  540. pPerUser->pWorkstations.MaximumLength = 0;
  541. pPerUser->pWorkstations.Length = 0;
  542. ScepFreeNameStatusList(pPerUser->pPrivilegesHeld);
  543. pPerUser->pPrivilegesHeld = NULL;
  544. ScepFree(pPerUser);
  545. } __except (EXCEPTION_EXECUTE_HANDLER) {
  546. ASSERT(FALSE);
  547. rc = SCESTATUS_INVALID_PARAMETER;
  548. }
  549. }
  550. break;
  551. default:
  552. return(SCESTATUS_INVALID_PARAMETER);
  553. }
  554. }
  555. return(rc);
  556. }
  557. SCESTATUS
  558. ScepResetSecurityPolicyArea(
  559. IN PSCE_PROFILE_INFO pProfileInfo
  560. )
  561. {
  562. INT i;
  563. if ( pProfileInfo != NULL ) {
  564. pProfileInfo->MinimumPasswordAge = SCE_NO_VALUE;
  565. pProfileInfo->MaximumPasswordAge = SCE_NO_VALUE;
  566. pProfileInfo->MinimumPasswordLength = SCE_NO_VALUE;
  567. pProfileInfo->PasswordComplexity = SCE_NO_VALUE;
  568. pProfileInfo->PasswordHistorySize = SCE_NO_VALUE;
  569. pProfileInfo->LockoutBadCount = SCE_NO_VALUE;
  570. pProfileInfo->ResetLockoutCount = SCE_NO_VALUE;
  571. pProfileInfo->LockoutDuration = SCE_NO_VALUE;
  572. pProfileInfo->RequireLogonToChangePassword = SCE_NO_VALUE;
  573. pProfileInfo->ForceLogoffWhenHourExpire = SCE_NO_VALUE;
  574. pProfileInfo->SecureSystemPartition = SCE_NO_VALUE;
  575. pProfileInfo->ClearTextPassword = SCE_NO_VALUE;
  576. pProfileInfo->LSAAnonymousNameLookup = SCE_NO_VALUE;
  577. for ( i=0; i<3; i++ ) {
  578. pProfileInfo->MaximumLogSize[i] = SCE_NO_VALUE;
  579. pProfileInfo->AuditLogRetentionPeriod[i] = SCE_NO_VALUE;
  580. pProfileInfo->RetentionDays[i] = SCE_NO_VALUE;
  581. pProfileInfo->RestrictGuestAccess[i] = SCE_NO_VALUE;
  582. }
  583. pProfileInfo->AuditSystemEvents = SCE_NO_VALUE;
  584. pProfileInfo->AuditLogonEvents = SCE_NO_VALUE;
  585. pProfileInfo->AuditObjectAccess = SCE_NO_VALUE;
  586. pProfileInfo->AuditPrivilegeUse = SCE_NO_VALUE;
  587. pProfileInfo->AuditPolicyChange = SCE_NO_VALUE;
  588. pProfileInfo->AuditAccountManage = SCE_NO_VALUE;
  589. pProfileInfo->AuditProcessTracking = SCE_NO_VALUE;
  590. pProfileInfo->AuditDSAccess = SCE_NO_VALUE;
  591. pProfileInfo->AuditAccountLogon = SCE_NO_VALUE;
  592. pProfileInfo->CrashOnAuditFull = SCE_NO_VALUE;
  593. if ( pProfileInfo->pKerberosInfo ) {
  594. pProfileInfo->pKerberosInfo->MaxTicketAge = SCE_NO_VALUE;
  595. pProfileInfo->pKerberosInfo->MaxRenewAge = SCE_NO_VALUE;
  596. pProfileInfo->pKerberosInfo->MaxServiceAge = SCE_NO_VALUE;
  597. pProfileInfo->pKerberosInfo->MaxClockSkew = SCE_NO_VALUE;
  598. pProfileInfo->pKerberosInfo->TicketValidateClient = SCE_NO_VALUE;
  599. }
  600. if ( pProfileInfo->RegValueCount && pProfileInfo->aRegValues ) {
  601. ScepFreeRegistryValues(&pProfileInfo->aRegValues,
  602. pProfileInfo->RegValueCount);
  603. }
  604. pProfileInfo->RegValueCount = 0;
  605. pProfileInfo->aRegValues = NULL;
  606. pProfileInfo->EnableAdminAccount = SCE_NO_VALUE;
  607. pProfileInfo->EnableGuestAccount = SCE_NO_VALUE;
  608. return(SCESTATUS_SUCCESS);
  609. } else {
  610. return(SCESTATUS_INVALID_PARAMETER);
  611. }
  612. }
  613. SCESTATUS
  614. WINAPI
  615. SceFreeProfileMemory(
  616. PSCE_PROFILE_INFO pProfile
  617. )
  618. {
  619. if ( pProfile == NULL )
  620. return(SCESTATUS_SUCCESS);
  621. switch ( pProfile->Type ) {
  622. case SCE_ENGINE_SCP:
  623. case SCE_ENGINE_SAP:
  624. case SCE_ENGINE_SMP:
  625. case SCE_ENGINE_SCP_INTERNAL:
  626. case SCE_ENGINE_SMP_INTERNAL:
  627. case SCE_STRUCT_INF:
  628. SceFreeMemory((PVOID)pProfile, AREA_ALL);
  629. ScepFree(pProfile);
  630. break;
  631. default:
  632. return(SCESTATUS_INVALID_PARAMETER);
  633. }
  634. return(SCESTATUS_SUCCESS);
  635. }
  636. SCESTATUS
  637. ScepFreePrivilege(
  638. IN PSCE_PRIVILEGE_ASSIGNMENT pRights
  639. )
  640. {
  641. PSCE_PRIVILEGE_ASSIGNMENT pTempRight;
  642. while ( pRights != NULL ) {
  643. if ( pRights->Name != NULL )
  644. ScepFree(pRights->Name);
  645. ScepFreeNameList(pRights->AssignedTo);
  646. pTempRight = pRights;
  647. pRights = pRights->Next;
  648. ScepFree( pTempRight );
  649. }
  650. return(SCESTATUS_SUCCESS);
  651. }
  652. SCESTATUS
  653. ScepFreeObjectSecurity(
  654. IN PSCE_OBJECT_ARRAY pObject
  655. )
  656. /* ++
  657. Routine Description:
  658. This routine frees memory associated with ppObject.
  659. Arguments:
  660. ppObject - buffer for object security
  661. Return value:
  662. SCESTATUS_SUCCESS
  663. -- */
  664. {
  665. PSCE_OBJECT_SECURITY pCurObject;
  666. DWORD i;
  667. if ( pObject == NULL )
  668. return(SCESTATUS_SUCCESS);
  669. for ( i=0; i<pObject->Count; i++ ) {
  670. pCurObject = pObject->pObjectArray[i];
  671. if ( pCurObject != NULL ) {
  672. if ( pCurObject->Name != NULL )
  673. ScepFree( pCurObject->Name );
  674. if ( pCurObject->pSecurityDescriptor != NULL )
  675. ScepFree(pCurObject->pSecurityDescriptor);
  676. // if ( pCurObject->SDspec != NULL )
  677. // ScepFree( pCurObject->SDspec );
  678. ScepFree( pCurObject );
  679. }
  680. }
  681. ScepFree(pObject);
  682. return(SCESTATUS_SUCCESS);
  683. }
  684. VOID
  685. SceFreePSCE_SERVICES(
  686. IN PSCE_SERVICES pServiceList
  687. )
  688. /*
  689. Routine Description:
  690. Free memory allocated in PSCE_SERVICES structure
  691. Arguments:
  692. pServiceList - the list of services node
  693. Return Value:
  694. none
  695. */
  696. {
  697. PSCE_SERVICES pTemp=pServiceList, pTemp2;
  698. while ( pTemp != NULL ) {
  699. //
  700. // ServiceName
  701. //
  702. if ( NULL != pTemp->ServiceName ) {
  703. LocalFree(pTemp->ServiceName);
  704. }
  705. //
  706. // display name
  707. //
  708. if ( NULL != pTemp->DisplayName ) {
  709. LocalFree(pTemp->DisplayName);
  710. }
  711. //
  712. // pSecurityDescriptor or ServiceEngineName
  713. // in same address
  714. //
  715. if ( NULL != pTemp->General.pSecurityDescriptor ) {
  716. LocalFree(pTemp->General.pSecurityDescriptor);
  717. }
  718. pTemp2 = pTemp;
  719. pTemp = pTemp->Next;
  720. // free the service node
  721. LocalFree(pTemp2);
  722. }
  723. return;
  724. }
  725. SCESTATUS
  726. ScepFreePrivilegeValueList(
  727. IN PSCE_PRIVILEGE_VALUE_LIST pPrivValueList
  728. )
  729. /* ++
  730. Routine Description:
  731. This routine frees memory associated with PSCE_PRIVILEGE_VALUE_LIST list
  732. Arguments:
  733. pPrivValueList - a PRIVILEGE_VALUE_LIST
  734. Return value:
  735. SCESTATUS_SUCCESS
  736. -- */
  737. {
  738. PSCE_PRIVILEGE_VALUE_LIST pCurName;
  739. PSCE_PRIVILEGE_VALUE_LIST pTempName;
  740. SCESTATUS rc=SCESTATUS_SUCCESS;
  741. if ( pPrivValueList == NULL )
  742. return(rc);
  743. pCurName = pPrivValueList;
  744. while ( pCurName != NULL ) {
  745. if ( pCurName->Name != NULL )
  746. __try {
  747. ScepFree( pCurName->Name );
  748. } __except (EXCEPTION_EXECUTE_HANDLER) {
  749. ASSERT(FALSE);
  750. rc = SCESTATUS_INVALID_PARAMETER;
  751. }
  752. pTempName = pCurName;
  753. pCurName = pCurName->Next;
  754. __try {
  755. ScepFree( pTempName );
  756. } __except (EXCEPTION_EXECUTE_HANDLER) {
  757. ASSERT(FALSE);
  758. rc = SCESTATUS_INVALID_PARAMETER;
  759. }
  760. }
  761. return(rc);
  762. }
  763. SCESTATUS
  764. ScepFreeNameStatusList(
  765. IN PSCE_NAME_STATUS_LIST pNameList
  766. )
  767. /* ++
  768. Routine Description:
  769. This routine frees memory associated with PSCE_NAME_STATUS_LIST pNameList
  770. Arguments:
  771. pNameList - a NAME_STATUS_LIST
  772. Return value:
  773. SCESTATUS_SUCCESS
  774. -- */
  775. {
  776. PSCE_NAME_STATUS_LIST pCurName;
  777. PSCE_NAME_STATUS_LIST pTempName;
  778. SCESTATUS rc=SCESTATUS_SUCCESS;
  779. if ( pNameList == NULL )
  780. return(rc);
  781. pCurName = pNameList;
  782. while ( pCurName != NULL ) {
  783. if ( pCurName->Name != NULL )
  784. __try {
  785. ScepFree( pCurName->Name );
  786. } __except (EXCEPTION_EXECUTE_HANDLER) {
  787. ASSERT(FALSE);
  788. rc = SCESTATUS_INVALID_PARAMETER;
  789. }
  790. pTempName = pCurName;
  791. pCurName = pCurName->Next;
  792. __try {
  793. ScepFree( pTempName );
  794. } __except (EXCEPTION_EXECUTE_HANDLER) {
  795. ASSERT(FALSE);
  796. rc = SCESTATUS_INVALID_PARAMETER;
  797. }
  798. }
  799. return(rc);
  800. }
  801. SCESTATUS
  802. ScepFreeGroupMembership(
  803. IN PSCE_GROUP_MEMBERSHIP pGroup
  804. )
  805. {
  806. PSCE_GROUP_MEMBERSHIP pTempGroup;
  807. while ( pGroup != NULL ) {
  808. if (pGroup->GroupName != NULL)
  809. ScepFree(pGroup->GroupName);
  810. //
  811. // free group members name list
  812. //
  813. ScepFreeNameList(pGroup->pMembers);
  814. ScepFreeNameList(pGroup->pMemberOf);
  815. ScepFreeNameStatusList(pGroup->pPrivilegesHeld);
  816. pTempGroup = pGroup;
  817. pGroup = pGroup->Next;
  818. ScepFree( pTempGroup );
  819. }
  820. return(SCESTATUS_SUCCESS);
  821. }
  822. SCESTATUS
  823. ScepFreeObjectList(
  824. IN PSCE_OBJECT_LIST pNameList
  825. )
  826. /* ++
  827. Routine Description:
  828. This routine frees memory associated with PSCE_OBJECT_LIST pNameList
  829. Arguments:
  830. pNameList - a OBJEcT_LIST
  831. Return value:
  832. SCESTATUS_SUCCESS
  833. -- */
  834. {
  835. PSCE_OBJECT_LIST pCurName;
  836. PSCE_OBJECT_LIST pTempName;
  837. SCESTATUS rc=SCESTATUS_SUCCESS;
  838. if ( pNameList == NULL )
  839. return(rc);
  840. pCurName = pNameList;
  841. while ( pCurName != NULL ) {
  842. if ( pCurName->Name != NULL )
  843. __try {
  844. ScepFree( pCurName->Name );
  845. } __except (EXCEPTION_EXECUTE_HANDLER) {
  846. ASSERT(FALSE);
  847. rc = SCESTATUS_INVALID_PARAMETER;
  848. }
  849. pTempName = pCurName;
  850. pCurName = pCurName->Next;
  851. __try {
  852. ScepFree( pTempName );
  853. } __except (EXCEPTION_EXECUTE_HANDLER) {
  854. ASSERT(FALSE);
  855. rc = SCESTATUS_INVALID_PARAMETER;
  856. }
  857. }
  858. return(rc);
  859. }
  860. SCESTATUS
  861. ScepFreeObjectChildren(
  862. IN PSCE_OBJECT_CHILDREN pNameArray
  863. )
  864. /* ++
  865. Routine Description:
  866. This routine frees memory associated with PSCE_OBJECT_LIST pNameList
  867. Arguments:
  868. pNameList - a OBJEcT_LIST
  869. Return value:
  870. SCESTATUS_SUCCESS
  871. -- */
  872. {
  873. SCESTATUS rc=SCESTATUS_SUCCESS;
  874. if ( pNameArray == NULL )
  875. return(rc);
  876. rc = ScepFreeObjectChildrenNode(pNameArray->nCount,
  877. &(pNameArray->arrObject));
  878. ScepFree(pNameArray);
  879. return(rc);
  880. }
  881. SCESTATUS
  882. ScepFreeObjectChildrenNode(
  883. IN DWORD Count,
  884. IN PSCE_OBJECT_CHILDREN_NODE *pArrObject
  885. )
  886. {
  887. SCESTATUS rc=SCESTATUS_SUCCESS;
  888. if ( NULL == pArrObject ) {
  889. return(rc);
  890. }
  891. DWORD i;
  892. for ( i=0; i<Count;i++) {
  893. if ( pArrObject[i] ) {
  894. if ( pArrObject[i]->Name ) {
  895. ScepFree( pArrObject[i]->Name );
  896. }
  897. ScepFree(pArrObject[i]);
  898. }
  899. }
  900. return(rc);
  901. }
  902. SCESTATUS
  903. SceSvcpFreeMemory(
  904. IN PVOID pvServiceInfo
  905. )
  906. {
  907. //
  908. // since PSCESVC_CONFIGURATION_INFO and PSCESVC_ANALYSIS_INFO contains
  909. // the same bytes, we just cast ServiceInfo to one type and free it.
  910. //
  911. if ( pvServiceInfo != NULL ) {
  912. __try {
  913. for ( DWORD i=0; i<*((DWORD *)pvServiceInfo); i++ ) {
  914. if ( ((PSCESVC_ANALYSIS_INFO)pvServiceInfo)->Lines[i].Key ) {
  915. ScepFree(((PSCESVC_ANALYSIS_INFO)pvServiceInfo)->Lines[i].Key);
  916. }
  917. if ( ((PSCESVC_ANALYSIS_INFO)pvServiceInfo)->Lines[i].Value ) {
  918. ScepFree(((PSCESVC_ANALYSIS_INFO)pvServiceInfo)->Lines[i].Value);
  919. }
  920. }
  921. ScepFree(((PSCESVC_ANALYSIS_INFO)pvServiceInfo)->Lines);
  922. ScepFree(pvServiceInfo);
  923. } __except(EXCEPTION_EXECUTE_HANDLER) {
  924. ASSERT(FALSE);
  925. return(SCESTATUS_INVALID_PARAMETER);
  926. }
  927. }
  928. return(SCESTATUS_SUCCESS);
  929. }