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.

1114 lines
31 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. svcsrv.cpp
  5. Abstract:
  6. Server Service attachment APIs
  7. Author:
  8. Jin Huang (jinhuang) 23-Jun-1997
  9. Revision History:
  10. jinhuang 23-Jan-1998 splitted to client-server
  11. --*/
  12. #include "serverp.h"
  13. #include "pfp.h"
  14. #include "srvrpcp.h"
  15. #include "service.h"
  16. #pragma hdrstop
  17. //
  18. // private prototypes
  19. //
  20. SCESTATUS
  21. SceSvcpGetOneKey(
  22. IN PSCESECTION hSection,
  23. IN PWSTR Prefix,
  24. IN DWORD PrefixLen,
  25. IN SCESVC_INFO_TYPE Type,
  26. OUT PVOID *Info
  27. );
  28. SCESTATUS
  29. SceSvcpEnumNext(
  30. IN PSCESECTION hSection,
  31. IN DWORD RequestCount,
  32. IN SCESVC_INFO_TYPE Type,
  33. OUT PVOID *Info,
  34. OUT PDWORD CountReturned
  35. );
  36. //
  37. // prototypes called from RPC interfaces
  38. //
  39. SCESTATUS
  40. SceSvcpUpdateInfo(
  41. IN PSCECONTEXT Context,
  42. IN PCWSTR ServiceName,
  43. IN PSCESVC_CONFIGURATION_INFO Info
  44. )
  45. /*
  46. Routine Description:
  47. Load service's engine dll and pass the Info buffer to service engine's
  48. update API (SceSvcAttachmentUpdate). Currently security manager engine
  49. is not doing any processing for the service data.
  50. This routine triggers the update of configuration database and/or
  51. analysis information by the service engine. Info may contain the
  52. modifications only, or the whole configuratio data for the service,
  53. or partial configuration data, depending on the agreement between service
  54. extension and service engine.
  55. This routine does not really write info to security manager database directly,
  56. instead, it passes the info buffer to the service engine's update interface
  57. and service engine will determine what and when to write inot the database.
  58. Arguments:
  59. hProfile - the security database context handle
  60. ServiceName - The service's name as used by service control manager
  61. Info - The information modified
  62. */
  63. {
  64. if ( Context == NULL || ServiceName == NULL ||
  65. Info == NULL ) {
  66. return(SCESTATUS_INVALID_PARAMETER);
  67. }
  68. SCESTATUS rc;
  69. //
  70. // get service's dll name
  71. //
  72. DWORD KeyLen;
  73. PWSTR KeyStr=NULL;
  74. KeyLen = wcslen(SCE_ROOT_SERVICE_PATH) + 1 + wcslen(ServiceName);
  75. KeyStr = (PWSTR)ScepAlloc(0, (KeyLen+1)*sizeof(WCHAR));
  76. if ( KeyStr == NULL ) {
  77. return(SCESTATUS_NOT_ENOUGH_RESOURCE);
  78. }
  79. PWSTR Setting=NULL;
  80. DWORD RegType;
  81. swprintf(KeyStr, L"%s\\%s", SCE_ROOT_SERVICE_PATH, ServiceName);
  82. KeyStr[KeyLen] = L'\0';
  83. rc = ScepRegQueryValue(
  84. HKEY_LOCAL_MACHINE,
  85. KeyStr,
  86. L"ServiceAttachmentPath",
  87. (PVOID *)&Setting,
  88. &RegType,
  89. NULL
  90. );
  91. rc = ScepDosErrorToSceStatus(rc);
  92. if ( rc == SCESTATUS_SUCCESS ) {
  93. if ( Setting != NULL ) {
  94. //
  95. // load the dll.
  96. //
  97. HINSTANCE hService;
  98. hService = LoadLibrary(Setting);
  99. if ( hService != NULL ) {
  100. //
  101. // call SceSvcAttachmentUpdate from the dll
  102. //
  103. PF_UpdateService pfTemp;
  104. pfTemp = (PF_UpdateService)
  105. GetProcAddress(hService,
  106. "SceSvcAttachmentUpdate") ;
  107. if ( pfTemp != NULL ) {
  108. SCEP_HANDLE sceHandle;
  109. SCESVC_CALLBACK_INFO sceCbInfo;
  110. sceHandle.hProfile = (PVOID)Context;
  111. sceHandle.ServiceName = ServiceName;
  112. sceCbInfo.sceHandle = &sceHandle;
  113. sceCbInfo.pfQueryInfo = &SceCbQueryInfo;
  114. sceCbInfo.pfSetInfo = &SceCbSetInfo;
  115. sceCbInfo.pfFreeInfo = &SceSvcpFreeMemory;
  116. sceCbInfo.pfLogInfo = &ScepLogOutput2;
  117. //
  118. // call the SceSvcAttachmentUpdate from the DLL
  119. //
  120. __try {
  121. rc = (*pfTemp)((PSCESVC_CALLBACK_INFO)&sceCbInfo, Info );
  122. } __except (EXCEPTION_EXECUTE_HANDLER) {
  123. rc = SCESTATUS_SERVICE_NOT_SUPPORT;
  124. }
  125. } else {
  126. //
  127. // this API is not supported
  128. //
  129. rc = SCESTATUS_SERVICE_NOT_SUPPORT;
  130. }
  131. //
  132. // try to free the library handle. If it fails, just leave it
  133. // to to the process to terminate
  134. //
  135. FreeLibrary(hService);
  136. } else
  137. rc = SCESTATUS_SERVICE_NOT_SUPPORT;
  138. ScepFree(Setting);
  139. } else
  140. rc = SCESTATUS_SERVICE_NOT_SUPPORT;
  141. }
  142. ScepFree(KeyStr);
  143. return(rc);
  144. }
  145. SCESTATUS
  146. SceSvcpQueryInfo(
  147. IN PSCECONTEXT Context,
  148. IN SCESVC_INFO_TYPE SceSvcType,
  149. IN PCWSTR ServiceName,
  150. IN PWSTR Prefix OPTIONAL,
  151. IN BOOL bExact,
  152. OUT PVOID *ppvInfo,
  153. IN OUT PSCE_ENUMERATION_CONTEXT psceEnumHandle
  154. )
  155. /*
  156. Routine Description:
  157. Query information for the service in the configuration/analysis database
  158. which contains the modified configuration and last analysis information.
  159. One enumeration returns maximum SCESVC_ENUMERATION_MAX lines (key/value)
  160. matching the lpPrefix for the service. If lpPrefix is NULL, all information
  161. for the service is enumerated. If there is more information, psceEnumHandle
  162. must be used to get next set of keys/values, until *ppvInfo is NULL or Count is 0.
  163. When bExact is set and lpPrefix is not NULL, exact match on the lpPrefix is
  164. searched and only one line is returned.
  165. The output buffer must be freed by SceSvcFree
  166. Arguments:
  167. Context - the database context handle
  168. SceSvcType - the information type to query
  169. ServiceName - the service name to query info for
  170. Prefix - the optional key name prefix for the query
  171. bExact - TRUE = exact match on key
  172. ppvInfo - the output buffer
  173. psceEnumHandle - the output enumeration handle for next enumeartion
  174. */
  175. {
  176. if ( Context == NULL || ppvInfo == NULL ||
  177. psceEnumHandle == NULL ) {
  178. return(SCESTATUS_INVALID_PARAMETER);
  179. }
  180. PSCESECTION hSection=NULL;
  181. DOUBLE SectionID;
  182. SCESTATUS rc;
  183. switch ( SceSvcType ) {
  184. case SceSvcConfigurationInfo:
  185. //
  186. // query data in configuration database
  187. //
  188. rc = ScepOpenSectionForName(
  189. Context,
  190. SCE_ENGINE_SMP,
  191. ServiceName,
  192. &hSection
  193. );
  194. break;
  195. case SceSvcAnalysisInfo:
  196. //
  197. // query data in analysis database
  198. //
  199. rc = ScepOpenSectionForName(
  200. Context,
  201. SCE_ENGINE_SAP,
  202. ServiceName,
  203. &hSection
  204. );
  205. break;
  206. case SceSvcInternalUse:
  207. case SceSvcMergedPolicyInfo:
  208. //
  209. // query data in SCP database
  210. //
  211. rc = SceJetGetSectionIDByName(
  212. Context,
  213. ServiceName,
  214. &SectionID
  215. );
  216. if ( rc == SCESTATUS_SUCCESS ) {
  217. rc = SceJetOpenSection(
  218. Context,
  219. SectionID,
  220. SCEJET_TABLE_SCP,
  221. &hSection
  222. );
  223. }
  224. break;
  225. default:
  226. rc = SCESTATUS_INVALID_PARAMETER;
  227. break;
  228. }
  229. if ( rc == SCESTATUS_SUCCESS ) {
  230. *ppvInfo = NULL;
  231. DWORD PrefixLen, CountReturned;
  232. if ( Prefix != NULL ) {
  233. PrefixLen = wcslen(Prefix);
  234. } else
  235. PrefixLen = 0;
  236. if ( bExact && Prefix != NULL ) {
  237. //
  238. // one single key match
  239. //
  240. rc = SceSvcpGetOneKey(
  241. hSection,
  242. Prefix,
  243. PrefixLen,
  244. SceSvcType,
  245. ppvInfo
  246. );
  247. *psceEnumHandle = 0;
  248. } else {
  249. //
  250. // count total number of lines matching Prefix
  251. //
  252. DWORD LineCount;
  253. rc = SceJetGetLineCount(
  254. hSection,
  255. Prefix,
  256. TRUE,
  257. &LineCount
  258. );
  259. if ( rc == SCESTATUS_SUCCESS && LineCount <= 0 )
  260. rc = SCESTATUS_RECORD_NOT_FOUND;
  261. if ( rc == SCESTATUS_SUCCESS ) {
  262. if ( LineCount <= *psceEnumHandle ) {
  263. //
  264. // no more entries
  265. //
  266. } else {
  267. //
  268. // go to the first line of Prefix
  269. //
  270. rc = SceJetSeek(
  271. hSection,
  272. Prefix,
  273. PrefixLen*sizeof(WCHAR),
  274. SCEJET_SEEK_GE
  275. );
  276. if ( rc == SCESTATUS_SUCCESS ) {
  277. //
  278. // skip the first *EnumHandle lines
  279. //
  280. JET_ERR JetErr;
  281. JetErr = JetMove(hSection->JetSessionID,
  282. hSection->JetTableID,
  283. *psceEnumHandle,
  284. 0
  285. );
  286. rc = SceJetJetErrorToSceStatus(JetErr);
  287. if ( rc == SCESTATUS_SUCCESS ) {
  288. //
  289. // find the right start point
  290. //
  291. DWORD CountToReturn;
  292. if ( LineCount - *psceEnumHandle > SCESVC_ENUMERATION_MAX ) {
  293. CountToReturn = SCESVC_ENUMERATION_MAX;
  294. } else
  295. CountToReturn = LineCount - *psceEnumHandle;
  296. //
  297. // get next block of data
  298. //
  299. rc = SceSvcpEnumNext(
  300. hSection,
  301. CountToReturn,
  302. SceSvcType,
  303. ppvInfo,
  304. &CountReturned
  305. );
  306. if ( rc == SCESTATUS_SUCCESS ) {
  307. //
  308. // update the enumeration handle
  309. //
  310. *psceEnumHandle += CountReturned;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. }
  317. if ( rc != SCESTATUS_SUCCESS ) {
  318. *psceEnumHandle = 0;
  319. }
  320. //
  321. // close the section
  322. //
  323. SceJetCloseSection(&hSection, TRUE);
  324. }
  325. return(rc);
  326. }
  327. SCESTATUS
  328. SceSvcpGetOneKey(
  329. IN PSCESECTION hSection,
  330. IN PWSTR Prefix,
  331. IN DWORD PrefixLen,
  332. IN SCESVC_INFO_TYPE Type,
  333. OUT PVOID *Info
  334. )
  335. /*
  336. Read key and value information into *Info for exact matched Prefix
  337. */
  338. {
  339. if ( hSection == NULL || Prefix == NULL ||
  340. Info == NULL ) {
  341. return(SCESTATUS_INVALID_PARAMETER);
  342. }
  343. SCESTATUS rc;
  344. DWORD ValueLen;
  345. PBYTE Value=NULL;
  346. rc = SceJetGetValue(
  347. hSection,
  348. SCEJET_EXACT_MATCH,
  349. Prefix,
  350. NULL,
  351. 0,
  352. NULL,
  353. NULL,
  354. 0,
  355. &ValueLen
  356. );
  357. if ( rc == SCESTATUS_SUCCESS ) {
  358. //
  359. // allocate buffer for Value
  360. //
  361. Value = (PBYTE)ScepAlloc(0, ValueLen+2);
  362. if ( Value != NULL ) {
  363. rc = SceJetGetValue(
  364. hSection,
  365. SCEJET_CURRENT,
  366. NULL,
  367. NULL,
  368. 0,
  369. NULL,
  370. (PWSTR)Value,
  371. ValueLen,
  372. &ValueLen
  373. );
  374. if ( rc == SCESTATUS_SUCCESS ) {
  375. //
  376. // allocate output buffer and assign
  377. //
  378. PSCESVC_ANALYSIS_INFO pAnalysisInfo=NULL;
  379. PSCESVC_CONFIGURATION_INFO pConfigInfo=NULL;
  380. if ( Type == SceSvcAnalysisInfo ) {
  381. *Info = ScepAlloc(0, sizeof(SCESVC_ANALYSIS_INFO));
  382. pAnalysisInfo = (PSCESVC_ANALYSIS_INFO)(*Info);
  383. } else {
  384. *Info = ScepAlloc(0, sizeof(SCESVC_CONFIGURATION_INFO));
  385. pConfigInfo = (PSCESVC_CONFIGURATION_INFO)(*Info);
  386. }
  387. if ( *Info != NULL ) {
  388. //
  389. // Lines buffer
  390. //
  391. if ( Type == SceSvcAnalysisInfo ) {
  392. pAnalysisInfo->Lines = (PSCESVC_ANALYSIS_LINE)ScepAlloc(0,
  393. sizeof(SCESVC_ANALYSIS_LINE));
  394. if ( pAnalysisInfo->Lines != NULL ) {
  395. //
  396. // Key buffer
  397. //
  398. pAnalysisInfo->Lines->Key = (PWSTR)ScepAlloc(0, (PrefixLen+1)*sizeof(WCHAR));
  399. if ( pAnalysisInfo->Lines->Key != NULL ) {
  400. wcscpy( pAnalysisInfo->Lines->Key, Prefix );
  401. pAnalysisInfo->Lines->Value = Value;
  402. pAnalysisInfo->Lines->ValueLen = ValueLen;
  403. pAnalysisInfo->Count = 1;
  404. Value = NULL;
  405. } else {
  406. //
  407. // free *Info->Lines
  408. //
  409. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  410. ScepFree( pAnalysisInfo->Lines );
  411. pAnalysisInfo->Lines = NULL;
  412. }
  413. } else
  414. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  415. if ( rc != SCESTATUS_SUCCESS ) {
  416. //
  417. // free buffer allocate
  418. //
  419. ScepFree(*Info);
  420. *Info = NULL;
  421. }
  422. } else {
  423. pConfigInfo->Lines = (PSCESVC_CONFIGURATION_LINE)ScepAlloc(0,
  424. sizeof(SCESVC_CONFIGURATION_LINE));
  425. if ( pConfigInfo->Lines != NULL ) {
  426. //
  427. // Key buffer
  428. //
  429. pConfigInfo->Lines->Key = (PWSTR)ScepAlloc(0, (PrefixLen+1)*sizeof(WCHAR));
  430. if ( pConfigInfo->Lines->Key != NULL ) {
  431. wcscpy( pConfigInfo->Lines->Key, Prefix );
  432. pConfigInfo->Lines->Value = (PWSTR)Value;
  433. pConfigInfo->Lines->ValueLen = ValueLen;
  434. pConfigInfo->Count = 1;
  435. Value = NULL;
  436. } else {
  437. //
  438. // free *Info->Lines
  439. //
  440. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  441. ScepFree( pConfigInfo->Lines );
  442. pConfigInfo->Lines = NULL;
  443. }
  444. } else
  445. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  446. if ( rc != SCESTATUS_SUCCESS ) {
  447. //
  448. // free buffer allocate
  449. //
  450. ScepFree(*Info);
  451. *Info = NULL;
  452. }
  453. }
  454. //
  455. // free *Info
  456. //
  457. if ( rc != SCESTATUS_SUCCESS ) {
  458. ScepFree( *Info );
  459. *Info = NULL;
  460. }
  461. } else
  462. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  463. }
  464. if ( Value != NULL ) {
  465. ScepFree(Value);
  466. Value = NULL;
  467. }
  468. }
  469. }
  470. return(rc);
  471. }
  472. SCESTATUS
  473. SceSvcpEnumNext(
  474. IN PSCESECTION hSection,
  475. IN DWORD RequestCount,
  476. IN SCESVC_INFO_TYPE Type,
  477. OUT PVOID *Info,
  478. OUT PDWORD CountReturned
  479. )
  480. {
  481. if ( hSection == NULL || Info == NULL || CountReturned == NULL ) {
  482. return(SCESTATUS_INVALID_PARAMETER);
  483. }
  484. if ( RequestCount <= 0 ) {
  485. *CountReturned = 0;
  486. return(SCESTATUS_SUCCESS);
  487. }
  488. SCESTATUS rc=SCESTATUS_SUCCESS;
  489. //
  490. // allocate output buffer
  491. //
  492. PSCESVC_ANALYSIS_INFO pAnalysisInfo=NULL;
  493. PSCESVC_CONFIGURATION_INFO pConfigInfo=NULL;
  494. if ( Type == SceSvcAnalysisInfo ) {
  495. *Info = ScepAlloc(0, sizeof(SCESVC_ANALYSIS_INFO));
  496. pAnalysisInfo = (PSCESVC_ANALYSIS_INFO)(*Info);
  497. } else {
  498. *Info = ScepAlloc(0, sizeof(SCESVC_CONFIGURATION_INFO));
  499. pConfigInfo = (PSCESVC_CONFIGURATION_INFO)(*Info);
  500. }
  501. if ( *Info != NULL ) {
  502. DWORD Count=0;
  503. if ( Type == SceSvcAnalysisInfo ) {
  504. pAnalysisInfo->Lines = (PSCESVC_ANALYSIS_LINE)ScepAlloc(0,
  505. RequestCount*sizeof(SCESVC_ANALYSIS_LINE));
  506. if ( pAnalysisInfo->Lines == NULL ) {
  507. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  508. }
  509. } else {
  510. pConfigInfo->Lines = (PSCESVC_CONFIGURATION_LINE)ScepAlloc(0,
  511. RequestCount*sizeof(SCESVC_CONFIGURATION_LINE));
  512. if ( pConfigInfo->Lines == NULL ) {
  513. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  514. }
  515. }
  516. if ( rc == SCESTATUS_SUCCESS ) { // if Lines is NULL, rc will be NOT_ENOUGH_RESOURCE
  517. //
  518. // loop through each line
  519. //
  520. DWORD KeyLen, ValueLen;
  521. PWSTR Key=NULL, Value=NULL;
  522. do {
  523. rc = SceJetGetValue(
  524. hSection,
  525. SCEJET_CURRENT,
  526. NULL,
  527. NULL,
  528. 0,
  529. &KeyLen,
  530. NULL,
  531. 0,
  532. &ValueLen
  533. );
  534. if ( rc == SCESTATUS_SUCCESS ) {
  535. //
  536. // allocate memory for the Key and Value
  537. //
  538. Key = (PWSTR)ScepAlloc(LMEM_ZEROINIT, KeyLen+2);
  539. Value = (PWSTR)ScepAlloc( LMEM_ZEROINIT, ValueLen+2);
  540. if ( Key == NULL || Value == NULL ) {
  541. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  542. ScepFree(Key);
  543. ScepFree(Value);
  544. } else {
  545. //
  546. // Get the Key and Value
  547. //
  548. rc = SceJetGetValue(
  549. hSection,
  550. SCEJET_CURRENT,
  551. NULL,
  552. Key,
  553. KeyLen,
  554. &KeyLen,
  555. Value,
  556. ValueLen,
  557. &ValueLen
  558. );
  559. if ( rc == SCESTATUS_SUCCESS ) {
  560. //
  561. // assign to the output buffer
  562. //
  563. if ( Type == SceSvcAnalysisInfo ) {
  564. pAnalysisInfo->Lines[Count].Key = Key;
  565. pAnalysisInfo->Lines[Count].Value = (PBYTE)Value;
  566. pAnalysisInfo->Lines[Count].ValueLen = ValueLen;
  567. } else {
  568. pConfigInfo->Lines[Count].Key = Key;
  569. pConfigInfo->Lines[Count].Value = Value;
  570. pConfigInfo->Lines[Count].ValueLen = ValueLen;
  571. }
  572. } else {
  573. ScepFree(Key);
  574. ScepFree(Value);
  575. }
  576. }
  577. }
  578. //
  579. // move to next line
  580. //
  581. if ( rc == SCESTATUS_SUCCESS ) {
  582. rc = SceJetMoveNext(hSection);
  583. Count++;
  584. }
  585. } while (rc == SCESTATUS_SUCCESS && Count < RequestCount );
  586. }
  587. *CountReturned = Count;
  588. if (Type == SceSvcAnalysisInfo) {
  589. pAnalysisInfo->Count = Count;
  590. } else {
  591. pConfigInfo->Count = Count;
  592. }
  593. if ( rc == SCESTATUS_RECORD_NOT_FOUND ) {
  594. rc = SCESTATUS_SUCCESS;
  595. } else if ( rc != SCESTATUS_SUCCESS ) {
  596. //
  597. // free memory allocated for output buffer
  598. //
  599. DWORD i;
  600. if (Type == SceSvcAnalysisInfo) {
  601. for ( i=0; i<Count; i++ ) {
  602. ScepFree(pAnalysisInfo->Lines[i].Key);
  603. ScepFree(pAnalysisInfo->Lines[i].Value);
  604. }
  605. ScepFree(pAnalysisInfo->Lines);
  606. } else {
  607. for ( i=0; i<Count; i++ ) {
  608. ScepFree(pConfigInfo->Lines[i].Key);
  609. ScepFree(pConfigInfo->Lines[i].Value);
  610. }
  611. ScepFree(pConfigInfo->Lines);
  612. }
  613. ScepFree(*Info);
  614. *Info = NULL;
  615. *CountReturned = 0;
  616. }
  617. } else
  618. rc = SCESTATUS_NOT_ENOUGH_RESOURCE;
  619. return(rc);
  620. }
  621. SCESTATUS
  622. SceSvcpSetInfo(
  623. IN PSCECONTEXT Context,
  624. IN SCESVC_INFO_TYPE SceSvcType,
  625. IN PCWSTR ServiceName,
  626. IN PWSTR Prefix OPTIONAL,
  627. IN BOOL bExact,
  628. IN LONG GpoID,
  629. IN PVOID pvInfo OPTIONAL
  630. )
  631. /*
  632. Routine Description:
  633. Save information of a service into security manager internal database. It's up
  634. to the service to collect/decide the information to write.
  635. Type indicates the type of internal database: CONFIGURATION or ANALYSIS.
  636. If the service section does not exist, create it.
  637. */
  638. {
  639. if (!Context || !ServiceName ) {
  640. return(SCESTATUS_INVALID_PARAMETER);
  641. }
  642. PSCESECTION hSection=NULL;
  643. SCESTATUS rc;
  644. //
  645. // open/create the sections
  646. //
  647. rc = SceJetStartTransaction( Context );
  648. if ( rc == SCESTATUS_SUCCESS ) {
  649. switch ( SceSvcType ) {
  650. case SceSvcConfigurationInfo:
  651. rc = ScepStartANewSection(
  652. Context,
  653. &hSection,
  654. SCEJET_TABLE_SMP,
  655. ServiceName
  656. );
  657. break;
  658. case SceSvcAnalysisInfo:
  659. rc = ScepStartANewSection(
  660. Context,
  661. &hSection,
  662. SCEJET_TABLE_SAP,
  663. ServiceName
  664. );
  665. break;
  666. case SceSvcInternalUse:
  667. case SceSvcMergedPolicyInfo:
  668. rc = ScepStartANewSection(
  669. Context,
  670. &hSection,
  671. SCEJET_TABLE_SCP,
  672. ServiceName
  673. );
  674. break;
  675. default:
  676. rc = SCESTATUS_INVALID_PARAMETER;
  677. }
  678. if ( rc == SCESTATUS_SUCCESS ) {
  679. if ( pvInfo == NULL ) {
  680. //
  681. // delete the whole section, partial for Prefix, or a single line
  682. //
  683. if (Prefix == NULL ) {
  684. rc = SceJetDelete(
  685. hSection,
  686. NULL,
  687. FALSE,
  688. SCEJET_DELETE_SECTION
  689. );
  690. } else if ( bExact ) {
  691. //
  692. // delete single line
  693. //
  694. rc = SceJetDelete(
  695. hSection,
  696. Prefix,
  697. FALSE,
  698. SCEJET_DELETE_LINE
  699. );
  700. } else {
  701. rc = SceJetDelete(
  702. hSection,
  703. Prefix,
  704. FALSE,
  705. SCEJET_DELETE_PARTIAL
  706. );
  707. }
  708. if ( rc == SCESTATUS_RECORD_NOT_FOUND ) {
  709. rc = SCESTATUS_SUCCESS;
  710. }
  711. } else {
  712. //
  713. // if bExact is not set, delete the whole section first
  714. //
  715. if ( !bExact ) {
  716. rc = SceJetDelete(
  717. hSection,
  718. NULL,
  719. FALSE,
  720. SCEJET_DELETE_SECTION
  721. );
  722. if ( rc == SCESTATUS_RECORD_NOT_FOUND ) {
  723. rc = SCESTATUS_SUCCESS;
  724. }
  725. }
  726. //
  727. // overwrite some keys in Info
  728. //
  729. DWORD Count;
  730. PWSTR Key;
  731. PBYTE Value;
  732. DWORD ValueLen;
  733. if ( SceSvcType == SceSvcAnalysisInfo )
  734. Count = ((PSCESVC_ANALYSIS_INFO)pvInfo)->Count;
  735. else
  736. Count = ((PSCESVC_CONFIGURATION_INFO)pvInfo)->Count;
  737. for ( DWORD i=0; i<Count; i++ ) {
  738. if ( SceSvcType == SceSvcAnalysisInfo ) {
  739. Key = ((PSCESVC_ANALYSIS_INFO)pvInfo)->Lines[i].Key;
  740. Value = ((PSCESVC_ANALYSIS_INFO)pvInfo)->Lines[i].Value;
  741. ValueLen = ((PSCESVC_ANALYSIS_INFO)pvInfo)->Lines[i].ValueLen;
  742. } else {
  743. Key = ((PSCESVC_CONFIGURATION_INFO)pvInfo)->Lines[i].Key;
  744. Value = (PBYTE)(((PSCESVC_CONFIGURATION_INFO)pvInfo)->Lines[i].Value);
  745. ValueLen = ((PSCESVC_CONFIGURATION_INFO)pvInfo)->Lines[i].ValueLen;
  746. }
  747. rc = SceJetSetLine(
  748. hSection,
  749. Key,
  750. TRUE,
  751. (PWSTR)Value,
  752. ValueLen,
  753. GpoID
  754. );
  755. if ( rc != SCESTATUS_SUCCESS ) {
  756. break;
  757. }
  758. }
  759. }
  760. }
  761. //
  762. // close the section
  763. //
  764. SceJetCloseSection(&hSection, TRUE);
  765. if ( rc == SCESTATUS_SUCCESS ) {
  766. //
  767. // commit the change
  768. //
  769. rc = SceJetCommitTransaction(Context, 0);
  770. }
  771. if ( rc != SCESTATUS_SUCCESS ) {
  772. SceJetRollback(Context, 0);
  773. }
  774. }
  775. return(rc);
  776. }
  777. //
  778. // attachment engine call back functions
  779. //
  780. SCESTATUS
  781. SceCbQueryInfo(
  782. IN SCE_HANDLE sceHandle,
  783. IN SCESVC_INFO_TYPE sceType,
  784. IN LPTSTR lpPrefix OPTIONAL,
  785. IN BOOL bExact,
  786. OUT PVOID *ppvInfo,
  787. OUT PSCE_ENUMERATION_CONTEXT psceEnumHandle
  788. )
  789. {
  790. PVOID hProfile;
  791. SCESTATUS rc=ERROR_SUCCESS;
  792. __try {
  793. hProfile = ((SCEP_HANDLE *)sceHandle)->hProfile;
  794. if ( !hProfile ||
  795. ((SCEP_HANDLE *)sceHandle)->ServiceName == NULL ) {
  796. rc = SCESTATUS_INVALID_PARAMETER;
  797. }
  798. } __except(EXCEPTION_EXECUTE_HANDLER) {
  799. rc = SCESTATUS_INVALID_PARAMETER;
  800. }
  801. if ( SCESTATUS_SUCCESS == rc ) {
  802. //
  803. // call the private function
  804. //
  805. rc = SceSvcpQueryInfo(
  806. (PSCECONTEXT)hProfile,
  807. sceType,
  808. ((SCEP_HANDLE *)sceHandle)->ServiceName,
  809. lpPrefix,
  810. bExact,
  811. ppvInfo,
  812. psceEnumHandle
  813. );
  814. }
  815. return(rc);
  816. }
  817. SCESTATUS
  818. SceCbSetInfo(
  819. IN SCE_HANDLE sceHandle,
  820. IN SCESVC_INFO_TYPE sceType,
  821. IN LPTSTR lpPrefix OPTIONAL,
  822. IN BOOL bExact,
  823. IN PVOID pvInfo
  824. )
  825. {
  826. PVOID hProfile;
  827. SCESTATUS rc=ERROR_SUCCESS;
  828. __try {
  829. hProfile = ((SCEP_HANDLE *)sceHandle)->hProfile;
  830. if ( !hProfile ||
  831. ((SCEP_HANDLE *)sceHandle)->ServiceName == NULL ) {
  832. rc = SCESTATUS_INVALID_PARAMETER;
  833. }
  834. } __except(EXCEPTION_EXECUTE_HANDLER) {
  835. rc = SCESTATUS_INVALID_PARAMETER;
  836. }
  837. if ( SCESTATUS_SUCCESS == rc ) {
  838. //
  839. // call the private function
  840. //
  841. rc = SceSvcpSetInfo(
  842. (PSCECONTEXT)hProfile,
  843. sceType,
  844. ((SCEP_HANDLE *)sceHandle)->ServiceName,
  845. lpPrefix,
  846. bExact,
  847. 0,
  848. pvInfo
  849. );
  850. }
  851. return(rc);
  852. }