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.

999 lines
28 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. logconf.c
  5. Abstract:
  6. This module contains the API routines that operate directly on logical
  7. configurations.
  8. CM_Add_Empty_Log_Conf
  9. CM_Free_Log_Conf
  10. CM_Get_First_Log_Conf
  11. CM_Get_Next_Log_Conf
  12. CM_Free_Log_Conf_Handle
  13. CM_Get_Log_Conf_Priority_Ex
  14. Author:
  15. Paula Tomlinson (paulat) 9-26-1995
  16. Environment:
  17. User mode only.
  18. Revision History:
  19. 26-Sept-1995 paulat
  20. Creation and initial implementation.
  21. --*/
  22. //
  23. // includes
  24. //
  25. #include "precomp.h"
  26. #pragma hdrstop
  27. #include "cfgi.h"
  28. //
  29. // Private prototypes
  30. //
  31. CONFIGRET
  32. CreateLogConfHandle(
  33. PLOG_CONF plcLogConf,
  34. DEVINST dnDevInst,
  35. ULONG ulLogType,
  36. ULONG ulLogTag
  37. );
  38. BOOL
  39. ValidateLogConfHandle(
  40. PPrivate_Log_Conf_Handle pLogConf
  41. );
  42. CONFIGRET
  43. CM_Add_Empty_Log_Conf_Ex(
  44. OUT PLOG_CONF plcLogConf,
  45. IN DEVINST dnDevInst,
  46. IN PRIORITY Priority,
  47. IN ULONG ulFlags,
  48. IN HMACHINE hMachine
  49. )
  50. /*++
  51. Routine Description:
  52. This routine creates an empty logical configuration. This configuration
  53. has no resource descriptor.
  54. Parameters:
  55. plcLogConf Address of a variable that receives the handle of the logical
  56. configuration.
  57. dnDevNode Handle of a device instance. This handle is typically
  58. retrieved by a call to CM_Locate_DevNode or CM_Create_DevNode.
  59. Priority Specifies the priority of the logical configuration.
  60. ulFlags Supplies flags relating to the logical configuration. Must
  61. be either BASIC_LOG_CONF or FILTERED_LOG_CONF, combined with
  62. either PRIORITY_EQUAL_FIRST or PRIORITY_EQUAL_LAST.
  63. BASIC_LOG_CONF - Specifies the requirements list
  64. FILTERED_LOG_CONF - Specifies the filtered requirements list
  65. PRIORITY_EQUAL_FIRST - Same priority, new one is first
  66. PRIORITY_EQUAL_LAST - Same priority, new one is last
  67. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  68. Return Value:
  69. If the function succeeds, the return value is CR_SUCCESS.
  70. If the function fails, the return value is one of the following:
  71. CR_INVALID_DEVNODE,
  72. CR_INVALID_FLAG,
  73. CR_INVALID_POINTER,
  74. CR_OUT_OF_MEMORY,
  75. CR_INVALID_PRIORITY,
  76. CR_INVALID_LOG_CONF.
  77. --*/
  78. {
  79. CONFIGRET Status = CR_SUCCESS;
  80. WCHAR pDeviceID [MAX_DEVICE_ID_LEN];
  81. ULONG ulTag = 0;
  82. ULONG ulLen = MAX_DEVICE_ID_LEN;
  83. PVOID hStringTable = NULL;
  84. handle_t hBinding = NULL;
  85. BOOL Success;
  86. try {
  87. //
  88. // validate parameters
  89. //
  90. if (dnDevInst == 0) {
  91. Status = CR_INVALID_DEVINST;
  92. goto Clean0;
  93. }
  94. if (plcLogConf == NULL) {
  95. Status = CR_INVALID_POINTER;
  96. goto Clean0;
  97. }
  98. if (Priority > MAX_LCPRI) {
  99. Status = CR_INVALID_PRIORITY;
  100. goto Clean0;
  101. }
  102. if (INVALID_FLAGS(ulFlags, LOG_CONF_BITS | PRIORITY_BIT)) {
  103. Status = CR_INVALID_FLAG;
  104. goto Clean0;
  105. }
  106. //
  107. // initialize output parameters
  108. //
  109. *plcLogConf = 0;
  110. //
  111. // setup rpc binding handle and string table handle
  112. //
  113. if (!PnPGetGlobalHandles(hMachine, &hStringTable, &hBinding)) {
  114. Status = CR_FAILURE;
  115. goto Clean0;
  116. }
  117. //
  118. // retreive device instance string that corresponds to dnDevInst
  119. //
  120. Success = pSetupStringTableStringFromIdEx(hStringTable, dnDevInst,pDeviceID,&ulLen);
  121. if (Success == FALSE || INVALID_DEVINST(pDeviceID)) {
  122. Status = CR_INVALID_DEVINST; // "input" devinst doesn't exist
  123. goto Clean0;
  124. }
  125. //
  126. // Special privileges are no longer required by the server.
  127. //
  128. // Note that with previous versions of the PlugPlay RPC server,
  129. // SE_LOAD_DRIVER_PRIVILEGE was required for this operation. We do not
  130. // need to enable the privilege for local callers, since this version of
  131. // CFGMGR32 should match a local version of UMPNPMGR that does not
  132. // require the privilege. For remote calls, it's not always possible
  133. // for us to enable the privilege anyways, since the client may not have
  134. // the privilege on the local machine, but may as authenticated on the
  135. // server. The server typically sees all privileges that a remote
  136. // caller has as "enabled by default", so we are not required to enable
  137. // the privilege here either.
  138. //
  139. RpcTryExcept {
  140. //
  141. // call rpc service entry point
  142. //
  143. Status = PNP_AddEmptyLogConf(
  144. hBinding, // rpc binding handle
  145. pDeviceID, // device id string
  146. Priority, // priority for new log conf
  147. &ulTag, // return tag of log conf
  148. ulFlags); // type of log conf to add
  149. }
  150. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  151. KdPrintEx((DPFLTR_PNPMGR_ID,
  152. DBGF_ERRORS,
  153. "PNP_AddEmptyLogConf caused an exception (%d)\n",
  154. RpcExceptionCode()));
  155. Status = MapRpcExceptionToCR(RpcExceptionCode());
  156. }
  157. RpcEndExcept
  158. //
  159. // If successful, allocate a new log conf handle, fill with log conf
  160. // info
  161. //
  162. if (Status == CR_SUCCESS) {
  163. Status = CreateLogConfHandle(
  164. plcLogConf, dnDevInst,
  165. ulFlags & LOG_CONF_BITS,
  166. ulTag);
  167. }
  168. Clean0:
  169. NOTHING;
  170. } except(EXCEPTION_EXECUTE_HANDLER) {
  171. Status = CR_FAILURE;
  172. }
  173. return Status;
  174. } // CM_Add_Empty_Log_Conf_Ex
  175. CONFIGRET
  176. CM_Free_Log_Conf_Ex(
  177. IN LOG_CONF lcLogConfToBeFreed,
  178. IN ULONG ulFlags,
  179. IN HMACHINE hMachine
  180. )
  181. /*++
  182. Routine Description:
  183. This routine frees a logical configuration and all resource descriptors
  184. associated with it. This API may invalidate the logical configuration
  185. handles returned by the CM_Get_First_Log_Conf and CM_Get_Next_Log_Conf
  186. APIs. To continue enumerating logical configurations, always use the
  187. CM_Get_First_Log_Conf API to start again from the beginning.
  188. Parameters:
  189. lcLogConfToBeFreed Supplies the handle of the logical configuration to
  190. free. This handle must have been previously returned from
  191. a call to CM_Add_Empty_Log_Conf.
  192. ulFlags Must be zero.
  193. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  194. Return Value:
  195. If the function succeeds, the return value is CR_SUCCESS.
  196. If the function fails, the return value is one of the following:
  197. CR_INVALID_FLAG,
  198. CR_INVALID_LOG_CONF.
  199. --*/
  200. {
  201. CONFIGRET Status = CR_SUCCESS;
  202. DEVINST dnDevInst;
  203. ULONG ulTag, ulType,ulLen = MAX_DEVICE_ID_LEN;
  204. WCHAR pDeviceID [MAX_DEVICE_ID_LEN];
  205. PVOID hStringTable = NULL;
  206. handle_t hBinding = NULL;
  207. BOOL Success;
  208. try {
  209. //
  210. // validate parameters
  211. //
  212. if (!ValidateLogConfHandle((PPrivate_Log_Conf_Handle)lcLogConfToBeFreed)) {
  213. Status = CR_INVALID_LOG_CONF;
  214. goto Clean0;
  215. }
  216. if (INVALID_FLAGS(ulFlags, 0)) {
  217. Status = CR_INVALID_FLAG;
  218. goto Clean0;
  219. }
  220. //
  221. // extract the devnode and log conf info from the log conf handle
  222. //
  223. dnDevInst = ((PPrivate_Log_Conf_Handle)lcLogConfToBeFreed)->LC_DevInst;
  224. ulTag = ((PPrivate_Log_Conf_Handle)lcLogConfToBeFreed)->LC_LogConfTag;
  225. ulType = ((PPrivate_Log_Conf_Handle)lcLogConfToBeFreed)->LC_LogConfType;
  226. //
  227. // setup rpc binding handle and string table handle
  228. //
  229. if (!PnPGetGlobalHandles(hMachine, &hStringTable, &hBinding)) {
  230. Status = CR_FAILURE;
  231. goto Clean0;
  232. }
  233. //
  234. // retreive device instance string that corresponds to dnDevInst
  235. //
  236. Success = pSetupStringTableStringFromIdEx(hStringTable, dnDevInst,pDeviceID,&ulLen);
  237. if (Success == FALSE || INVALID_DEVINST(pDeviceID)) {
  238. Status = CR_INVALID_LOG_CONF;
  239. goto Clean0;
  240. }
  241. KdPrintEx((DPFLTR_PNPMGR_ID,
  242. DBGF_REGISTRY,
  243. "CM_Free_Log_Conf_Ex: Deleting LogConf (pDeviceID = %s, Type = %d\r\n",
  244. pDeviceID,
  245. ulType));
  246. //
  247. // Special privileges are no longer required by the server.
  248. //
  249. // Note that with previous versions of the PlugPlay RPC server,
  250. // SE_LOAD_DRIVER_PRIVILEGE was required for this operation. We do not
  251. // need to enable the privilege for local callers, since this version of
  252. // CFGMGR32 should match a local version of UMPNPMGR that does not
  253. // require the privilege. For remote calls, it's not always possible
  254. // for us to enable the privilege anyways, since the client may not have
  255. // the privilege on the local machine, but may as authenticated on the
  256. // server. The server typically sees all privileges that a remote
  257. // caller has as "enabled by default", so we are not required to enable
  258. // the privilege here either.
  259. //
  260. RpcTryExcept {
  261. //
  262. // call rpc service entry point
  263. //
  264. Status = PNP_FreeLogConf(
  265. hBinding, // rpc binding handle
  266. pDeviceID, // device id string
  267. ulType, // identifies which type of log conf
  268. ulTag, // identifies which actual log conf
  269. ulFlags); // not used
  270. }
  271. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  272. KdPrintEx((DPFLTR_PNPMGR_ID,
  273. DBGF_ERRORS,
  274. "PNP_FreeLogConf caused an exception (%d)\n",
  275. RpcExceptionCode()));
  276. Status = MapRpcExceptionToCR(RpcExceptionCode());
  277. }
  278. RpcEndExcept
  279. Clean0:
  280. NOTHING;
  281. } except(EXCEPTION_EXECUTE_HANDLER) {
  282. Status = CR_INVALID_LOG_CONF; // probably a bad log conf got us here
  283. }
  284. return Status;
  285. } // CM_Free_Log_Conf_Ex
  286. CONFIGRET
  287. CM_Get_First_Log_Conf_Ex(
  288. OUT PLOG_CONF plcLogConf, OPTIONAL
  289. IN DEVINST dnDevInst,
  290. IN ULONG ulFlags,
  291. IN HMACHINE hMachine
  292. )
  293. /*++
  294. Routine Description:
  295. This routine returns a handle to the first logical configuration of the
  296. specified type in a device instance. The CM_Add_Empty_Log_Conf and
  297. CM_Free_Log_Conf APIs may invalidate the handle of the logical
  298. configuration returned by this API. To enumerate logical configurations
  299. after adding or freeing a logical configuration, always call this API
  300. again to retrieve a valid handle.
  301. Parameters:
  302. plcLogConf Supplies the address of the variable that receives the handle
  303. of the logical configuration.
  304. dnDevNode Supplies the handle of the device instance for which to
  305. retrieve the logical configuration.
  306. ulFlags Configuration type. Can be one of the following values:
  307. ALLOC_LOG_CONF - Retrieve the allocated configuration.
  308. BASIC_LOG_CONF - Retrieve the requirements list.
  309. BOOT_LOG_CONF - Retrieve the boot configuration.
  310. The following additional configuration type is also defined
  311. for Windows 95:
  312. FILTERED_LOG_CONF - Retrieve the filtered requirements list.
  313. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  314. Return Value:
  315. If the function succeeds, the return value is CR_SUCCESS.
  316. If the function fails, the return value is one of the following:
  317. CR_INVALID_DEVNODE,
  318. CR_INVALID_FLAG,
  319. CR_INVALID_POINTER,
  320. CR_NO_MORE_LOF_CONF.
  321. --*/
  322. {
  323. CONFIGRET Status = CR_SUCCESS;
  324. WCHAR pDeviceID [MAX_DEVICE_ID_LEN];
  325. ULONG ulTag = 0,ulLen = MAX_DEVICE_ID_LEN;
  326. PVOID hStringTable = NULL;
  327. handle_t hBinding = NULL;
  328. BOOL Success;
  329. try {
  330. //
  331. // validate parameters
  332. //
  333. if (dnDevInst == 0) {
  334. Status = CR_INVALID_DEVINST;
  335. goto Clean0;
  336. }
  337. if (INVALID_FLAGS(ulFlags, LOG_CONF_BITS)) {
  338. Status = CR_INVALID_FLAG;
  339. goto Clean0;
  340. }
  341. //
  342. // Initialize paramters (plcLogConf is optional)
  343. //
  344. if (plcLogConf != NULL) {
  345. *plcLogConf = 0;
  346. }
  347. //
  348. // setup rpc binding handle and string table handle
  349. //
  350. if (!PnPGetGlobalHandles(hMachine, &hStringTable, &hBinding)) {
  351. Status = CR_FAILURE;
  352. goto Clean0;
  353. }
  354. //
  355. // retreive device instance string that corresponds to dnDevInst
  356. //
  357. Success = pSetupStringTableStringFromIdEx(hStringTable, dnDevInst,pDeviceID,&ulLen);
  358. if (Success == FALSE || INVALID_DEVINST(pDeviceID)) {
  359. Status = CR_INVALID_DEVINST; // "input" devinst doesn't exist
  360. goto Clean0;
  361. }
  362. //
  363. // No special privileges are required by the server
  364. //
  365. RpcTryExcept {
  366. //
  367. // call rpc service entry point
  368. //
  369. Status = PNP_GetFirstLogConf(
  370. hBinding, // rpc binding handle
  371. pDeviceID, // device id string
  372. ulFlags, // type of long conf
  373. &ulTag, // return tag of specific log conf
  374. ulFlags); // not used
  375. }
  376. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  377. KdPrintEx((DPFLTR_PNPMGR_ID,
  378. DBGF_ERRORS,
  379. "PNP_GetFirstLogConf caused an exception (%d)\n",
  380. RpcExceptionCode()));
  381. Status = MapRpcExceptionToCR(RpcExceptionCode());
  382. }
  383. RpcEndExcept
  384. if (Status == CR_SUCCESS && plcLogConf != NULL) {
  385. //
  386. // allocate a new log conf handle, fill with log conf info
  387. //
  388. Status = CreateLogConfHandle(plcLogConf, dnDevInst,
  389. ulFlags & LOG_CONF_BITS,
  390. ulTag);
  391. }
  392. Clean0:
  393. NOTHING;
  394. } except(EXCEPTION_EXECUTE_HANDLER) {
  395. Status = CR_FAILURE;
  396. }
  397. return Status;
  398. } // CM_Get_First_Log_Conf_Ex
  399. CONFIGRET
  400. CM_Get_Next_Log_Conf_Ex(
  401. OUT PLOG_CONF plcLogConf, OPTIONAL
  402. IN LOG_CONF lcLogConf,
  403. IN ULONG ulFlags,
  404. IN HMACHINE hMachine
  405. )
  406. /*++
  407. Routine Description:
  408. This routine returns a handle to the next logical configuration following
  409. the given configuration. This API returns CR_NO_MORE_LOG_CONF if the given
  410. handle was retrieved using the CM_Get_First_Log_Conf API with either the
  411. ALLOC_LOG_CONF or BOOT_LOG_CONF flag. There is never more than one active
  412. boot logical configuration or currently-allocated logical configuration.
  413. The CM_Add_Empty_Log_Conf and CM_Free_Log_Conf APIs may invalidate the
  414. logical configuration handle returned by this API. To continue enumerating
  415. logical configuration after addding or freeing a logical configuration,
  416. always use the CM_Get_First_Log_Conf API to start again from the beginning.
  417. Parameters:
  418. plcLogConf Supplies the address of the variable that receives the handle
  419. of the next logical configuration.
  420. lcLogConf Supplies the handle of a logical configuration. This handle
  421. must have been previously retrieved using either this API or
  422. the CM_Get_First_Log_Conf API. Logical configurations are in
  423. priority order.
  424. ulFlags Must be zero.
  425. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  426. Return Value:
  427. If the function succeeds, the return value is CR_SUCCESS.
  428. If the function fails, the return value is one of the following:
  429. CR_INVALID_FLAG,
  430. CR_INVALID_LOG_CONF,
  431. CR_INVALID_POINTER,
  432. CR_NO_MORE_LOG_CONF.
  433. --*/
  434. {
  435. CONFIGRET Status = CR_SUCCESS;
  436. DEVINST dnDevInst;
  437. WCHAR pDeviceID [MAX_DEVICE_ID_LEN];
  438. ULONG ulType = 0, ulCurrentTag = 0, ulNextTag = 0,ulLen = MAX_DEVICE_ID_LEN;
  439. PVOID hStringTable = NULL;
  440. handle_t hBinding = NULL;
  441. BOOL Success;
  442. try {
  443. //
  444. // validate parameters
  445. //
  446. if (!ValidateLogConfHandle((PPrivate_Log_Conf_Handle)lcLogConf)) {
  447. Status = CR_INVALID_LOG_CONF;
  448. goto Clean0;
  449. }
  450. if (INVALID_FLAGS(ulFlags, 0)) {
  451. Status = CR_INVALID_FLAG;
  452. goto Clean0;
  453. }
  454. //
  455. // Initialize paramters (plcLogConf is optional)
  456. //
  457. if (plcLogConf != NULL) {
  458. *plcLogConf = 0;
  459. }
  460. //
  461. // extract devnode and log conf info from the current log conf handle
  462. //
  463. dnDevInst = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_DevInst;
  464. ulType = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_LogConfType;
  465. ulCurrentTag = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_LogConfTag;
  466. //
  467. // setup rpc binding handle and string table handle
  468. //
  469. if (!PnPGetGlobalHandles(hMachine, &hStringTable, &hBinding)) {
  470. Status = CR_FAILURE;
  471. goto Clean0;
  472. }
  473. //
  474. // retreive device instance string that corresponds to dnDevInst
  475. //
  476. Success = pSetupStringTableStringFromIdEx(hStringTable, dnDevInst,pDeviceID,&ulLen);
  477. if (Success == FALSE || INVALID_DEVINST(pDeviceID)) {
  478. Status = CR_INVALID_LOG_CONF;
  479. goto Clean0;
  480. }
  481. //
  482. // No special privileges are required by the server
  483. //
  484. RpcTryExcept {
  485. //
  486. // call rpc service entry point
  487. //
  488. Status = PNP_GetNextLogConf(
  489. hBinding, // rpc binding handle
  490. pDeviceID, // device id string
  491. ulType, // specifes which type of log conf
  492. ulCurrentTag, // specifies current log conf tag
  493. &ulNextTag, // return tag of next log conf
  494. ulFlags); // not used
  495. }
  496. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  497. KdPrintEx((DPFLTR_PNPMGR_ID,
  498. DBGF_ERRORS,
  499. "PNP_GetNextLogConf caused an exception (%d)\n",
  500. RpcExceptionCode()));
  501. Status = MapRpcExceptionToCR(RpcExceptionCode());
  502. }
  503. RpcEndExcept
  504. if (Status == CR_SUCCESS && plcLogConf != NULL) {
  505. //
  506. // allocate a new log conf handle, fill with log conf info
  507. //
  508. Status = CreateLogConfHandle(plcLogConf, dnDevInst,
  509. ulType, ulNextTag);
  510. }
  511. Clean0:
  512. NOTHING;
  513. } except(EXCEPTION_EXECUTE_HANDLER) {
  514. Status = CR_FAILURE;
  515. }
  516. return Status;
  517. } // CM_Get_Next_Log_Conf_Ex
  518. CONFIGRET
  519. CM_Free_Log_Conf_Handle(
  520. IN LOG_CONF lcLogConf
  521. )
  522. /*++
  523. Routine Description:
  524. This routine frees the handle to the specified log conf and frees and
  525. memory associated with that log conf handle.
  526. Parameters:
  527. lcLogConf Supplies the handle of a logical configuration. This handle
  528. must have been previously retrieved using CM_Add_Empty_Log_Conf,
  529. CM_Get_First_Log_Conf or CM_Get_Next_Log_Conf.
  530. Return Value:
  531. If the function succeeds, the return value is CR_SUCCESS.
  532. If the function fails, the return value is one of the following:
  533. CR_INVALID_LOG_CONF.
  534. --*/
  535. {
  536. CONFIGRET Status = CR_SUCCESS;
  537. try {
  538. //
  539. // Validate parameters
  540. //
  541. if (!ValidateLogConfHandle((PPrivate_Log_Conf_Handle)lcLogConf)) {
  542. Status = CR_INVALID_LOG_CONF;
  543. goto Clean0;
  544. }
  545. //
  546. // It's a valid log conf handle, which is a pointer to memory
  547. // allocated when the log conf was created or retrieved using
  548. // the first/next routines. Free the associated memory.
  549. //
  550. ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_Signature = 0;
  551. pSetupFree((PPrivate_Log_Conf_Handle)lcLogConf);
  552. Clean0:
  553. NOTHING;
  554. } except(EXCEPTION_EXECUTE_HANDLER) {
  555. Status = CR_FAILURE;
  556. }
  557. return Status;
  558. } // CM_Free_Log_Conf_Handle
  559. CMAPI
  560. CONFIGRET
  561. WINAPI
  562. CM_Get_Log_Conf_Priority_Ex(
  563. IN LOG_CONF lcLogConf,
  564. OUT PPRIORITY pPriority,
  565. IN ULONG ulFlags,
  566. IN HMACHINE hMachine
  567. )
  568. /*++
  569. Routine Description:
  570. This routine returns the priority value of the specified log conf.
  571. Only BASIC, FILTERED and OVERRIDE log confs (requirements lists) have
  572. a priority value associated with them. If a FORCED, BOOT, or ALLOC
  573. config is passed in, then CR_INVALID_LOG_CONF will be returned.
  574. Parameters:
  575. lcLogConf Supplies the handle of a logical configuration. This handle
  576. must have been previously retrieved using either the
  577. CM_Add_Emptry_Log_Conf, CM_Get_First_Log_Conf, or
  578. CM_Get_Next_Log_Conf API.
  579. pPriority Supplies the address of the variable that receives the
  580. priorty (if any) associated with this logical configuration.
  581. ulFlags Must be zero.
  582. hMachine Machine handle returned from CM_Connect_Machine or NULL.
  583. Return Value:
  584. If the function succeeds, the return value is CR_SUCCESS.
  585. If the function fails, the return value is one of the following:
  586. CR_INVALID_FLAG,
  587. CR_INVALID_LOG_CONF,
  588. CR_INVALID_POINTER,
  589. CR_NO_MORE_LOG_CONF.
  590. --*/
  591. {
  592. CONFIGRET Status = CR_SUCCESS;
  593. DEVINST dnDevInst;
  594. WCHAR pDeviceID [MAX_DEVICE_ID_LEN];
  595. ULONG ulType = 0, ulTag = 0,ulLen = MAX_DEVICE_ID_LEN;
  596. PVOID hStringTable = NULL;
  597. handle_t hBinding = NULL;
  598. BOOL Success;
  599. try {
  600. //
  601. // validate parameters
  602. //
  603. if (!ValidateLogConfHandle((PPrivate_Log_Conf_Handle)lcLogConf)) {
  604. Status = CR_INVALID_LOG_CONF;
  605. goto Clean0;
  606. }
  607. if (INVALID_FLAGS(ulFlags, 0)) {
  608. Status = CR_INVALID_FLAG;
  609. goto Clean0;
  610. }
  611. if (pPriority == NULL) {
  612. Status = CR_INVALID_POINTER;
  613. goto Clean0;
  614. }
  615. //
  616. // extract devnode and log conf info from the current log conf handle
  617. //
  618. dnDevInst = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_DevInst;
  619. ulType = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_LogConfType;
  620. ulTag = ((PPrivate_Log_Conf_Handle)lcLogConf)->LC_LogConfTag;
  621. //
  622. // only "requirements list" style log confs have priorities and
  623. // are valid in this call.
  624. //
  625. if ((ulType != BASIC_LOG_CONF) &&
  626. (ulType != FILTERED_LOG_CONF) &&
  627. (ulType != OVERRIDE_LOG_CONF)) {
  628. Status = CR_INVALID_LOG_CONF;
  629. goto Clean0;
  630. }
  631. //
  632. // setup rpc binding handle and string table handle
  633. //
  634. if (!PnPGetGlobalHandles(hMachine, &hStringTable, &hBinding)) {
  635. Status = CR_FAILURE;
  636. goto Clean0;
  637. }
  638. //
  639. // retreive device instance string that corresponds to dnDevInst
  640. //
  641. Success = pSetupStringTableStringFromIdEx(hStringTable, dnDevInst,pDeviceID,&ulLen);
  642. if (Success == FALSE || INVALID_DEVINST(pDeviceID)) {
  643. Status = CR_INVALID_LOG_CONF;
  644. goto Clean0;
  645. }
  646. //
  647. // No special privileges are required by the server
  648. //
  649. RpcTryExcept {
  650. //
  651. // call rpc service entry point
  652. //
  653. Status = PNP_GetLogConfPriority(
  654. hBinding, // rpc binding handle
  655. pDeviceID, // device id string
  656. ulType, // specifes which type of log conf
  657. ulTag, // specifies current log conf tag
  658. pPriority, // return tag of next log conf
  659. ulFlags); // not used
  660. }
  661. RpcExcept (I_RpcExceptionFilter(RpcExceptionCode())) {
  662. KdPrintEx((DPFLTR_PNPMGR_ID,
  663. DBGF_ERRORS,
  664. "PNP_GetLogConfPriority caused an exception (%d)\n",
  665. RpcExceptionCode()));
  666. Status = MapRpcExceptionToCR(RpcExceptionCode());
  667. }
  668. RpcEndExcept
  669. Clean0:
  670. NOTHING;
  671. } except(EXCEPTION_EXECUTE_HANDLER) {
  672. Status = CR_FAILURE;
  673. }
  674. return Status;
  675. } // CM_Free_Log_Conf_Handle
  676. //-------------------------------------------------------------------
  677. // Local Stubs
  678. //-------------------------------------------------------------------
  679. CONFIGRET
  680. CM_Add_Empty_Log_Conf(
  681. OUT PLOG_CONF plcLogConf,
  682. IN DEVINST dnDevInst,
  683. IN PRIORITY Priority,
  684. IN ULONG ulFlags
  685. )
  686. {
  687. return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
  688. ulFlags, NULL);
  689. }
  690. CONFIGRET
  691. CM_Free_Log_Conf(
  692. IN LOG_CONF lcLogConfToBeFreed,
  693. IN ULONG ulFlags
  694. )
  695. {
  696. return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
  697. }
  698. CONFIGRET
  699. CM_Get_First_Log_Conf(
  700. OUT PLOG_CONF plcLogConf,
  701. IN DEVINST dnDevInst,
  702. IN ULONG ulFlags
  703. )
  704. {
  705. return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
  706. }
  707. CONFIGRET
  708. CM_Get_Next_Log_Conf(
  709. OUT PLOG_CONF plcLogConf,
  710. IN LOG_CONF lcLogConf,
  711. IN ULONG ulFlags
  712. )
  713. {
  714. return CM_Get_Next_Log_Conf_Ex(plcLogConf, lcLogConf, ulFlags, NULL);
  715. }
  716. CMAPI
  717. CONFIGRET
  718. WINAPI
  719. CM_Get_Log_Conf_Priority(
  720. IN LOG_CONF lcLogConf,
  721. OUT PPRIORITY pPriority,
  722. IN ULONG ulFlags
  723. )
  724. {
  725. return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
  726. }
  727. //-------------------------------------------------------------------
  728. // Local Utility Routines
  729. //-------------------------------------------------------------------
  730. CONFIGRET
  731. CreateLogConfHandle(
  732. PLOG_CONF plcLogConf,
  733. DEVINST dnDevInst,
  734. ULONG ulLogType,
  735. ULONG ulLogTag
  736. )
  737. {
  738. PPrivate_Log_Conf_Handle pLogConfHandle;
  739. //
  740. // allocate memory for the res des handle data
  741. //
  742. pLogConfHandle = (PPrivate_Log_Conf_Handle)pSetupMalloc(
  743. sizeof(Private_Log_Conf_Handle));
  744. if (pLogConfHandle == NULL) {
  745. return CR_OUT_OF_MEMORY;
  746. }
  747. //
  748. // fill in the private res des info and return as handle
  749. //
  750. pLogConfHandle->LC_Signature = CM_PRIVATE_LOGCONF_SIGNATURE;
  751. pLogConfHandle->LC_DevInst = dnDevInst;
  752. pLogConfHandle->LC_LogConfType = ulLogType;
  753. pLogConfHandle->LC_LogConfTag = ulLogTag;
  754. *plcLogConf = (LOG_CONF)pLogConfHandle;
  755. return CR_SUCCESS;
  756. } // CreateLogConfHandle
  757. BOOL
  758. ValidateLogConfHandle(
  759. PPrivate_Log_Conf_Handle pLogConf
  760. )
  761. {
  762. //
  763. // validate parameters
  764. //
  765. if (pLogConf == NULL || pLogConf == 0) {
  766. return FALSE;
  767. }
  768. //
  769. // check for the private log conf signature
  770. //
  771. if (pLogConf->LC_Signature != CM_PRIVATE_LOGCONF_SIGNATURE) {
  772. return FALSE;
  773. }
  774. return TRUE;
  775. } // ValidateLogConfHandle