System services registered with Samgr can be accessed by other processes through IPC APIs. When a process requests to access such an API, IPC authentication is triggered to check whether the process has the required permission. If the process does not have the required permission, the access request will be denied.
System services registered with Samgr can be accessed by other processes through IPC APIs. When a process requests to access such an API, IPC authentication is triggered to check whether the process has the required permission. If the process does not have the required permission, the access request will be denied.
When developing a system service, you can use the IPC authentication component to configure access policies for APIs of the service. When other services access these APIs through IPC, Samgr calls APIs of the IPC authentication component to check whether the services have the access permission.
When developing a system service, you can use the IPC authentication component to configure access policies for APIs of the service. When other processes access these APIs through IPC, Samgr calls APIs of the IPC authentication component to check whether the processes have the access permission.
## Available APIs<a name="section1633115419401"></a>
## Available APIs<a name="section1633115419401"></a>
The following table lists the APIs provided by IPC authentication \(intended for Samgr only\).
The following table lists the APIs provided by IPC authentication \(intended for Samgr only\).
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p134951921115511"><aname="p134951921115511"></a><aname="p134951921115511"></a>Checks whether a process has the permission to access an API of another process.</p>
<tdclass="cellrowborder"valign="top"width="50%"headers="mcps1.2.3.1.2 "><pid="p134951921115511"><aname="p134951921115511"></a><aname="p134951921115511"></a>Checks whether a process has the permission to access an API of another service.</p>
</td>
</td>
</tr>
</tr>
</tbody>
</tbody>
...
@@ -39,15 +39,15 @@ The following table lists the APIs provided by IPC authentication \(intended for
...
@@ -39,15 +39,15 @@ The following table lists the APIs provided by IPC authentication \(intended for
## How to Develop<a name="section022611498210"></a>
## How to Develop<a name="section022611498210"></a>
This section uses BMS as an example to describe how to configure access policies for APIs provided by the IPC authentication component. In this example, the service registered by BMS with Samgr is **bundlems**, and the feature registered for open APIs is **BmsFeature**.
This section uses BMS as an example to describe how to configure access policies for APIs provided by the IPC authentication component. In this example, the service registered by BMS with Samgr is **bundlems**, and the feature registered for open APIs is**BmsFeature**.
1.<aname="li15901515152517"></a>Configure access policies in the **base/security/permission/services/permission\_lite/ipc\_auth/include/policy\_preset.h** file. Access policies are classified into the following three types:
1.<aname="li15901515152517"></a>On the OpenHarmony side, configure access policies in the **base/security/permission/services/permission\_lite/ipc\_auth/include/policy\_preset.h** file. On the device side, configure access policies in the **vendor/hisilicon/product_name/hals/security/permission\_lite/ipc\_auth/include/policy\_preset\_product.h** file (replace product_name with the actual product name). After that, set **POLICY\_PRODUCT** in the header files to **1**. Access policies are classified into the following three types:
1. **RANGE**: Processes with a specified range of UIDs can access BMS APIs. **uidMin** and **uidMax** must be specified.
1. **RANGE**: Processes with a specified range of UIDs can access BMS APIs. **uidMin** and **uidMax** must be specified.
2. **FIXED**: Processes with specified UIDs can access BMS APIs. **fixedUid** must be specified, and a maximum of eight UIDs are allowed.
2. **FIXED**: Processes with specified UIDs can access BMS APIs. **fixedUid** must be specified, and a maximum of eight UIDs are allowed.
3. **BUNDLENAME**: An application with a specified **bundleName** can access BMS APIs.
3. **BUNDLENAME**: An application with a specified **bundleName** can access BMS APIs.
```
```
FeaturePolicy bmsFeature[] = {
FeaturePolicy bmsFeature[] = {
...
@@ -82,13 +82,13 @@ This section uses BMS as an example to describe how to configure access policies
...
@@ -82,13 +82,13 @@ This section uses BMS as an example to describe how to configure access policies
};
};
```
```
2. Add the policies configured for the features in [Step 1](#li15901515152517) to the global policy settings. You need to set the number of features.
2. Add the policies configured for the features in [Step 1](#li15901515152517) to the global policy settings. You need to set the number of features.
```
```
static PolicySetting g_presetPolicies[] = {
static PolicySetting g_presetPolicies[] = {
{"permissionms", pmsFeature, 1},
{"permissionms", pmsFeature, 1},
{"abilityms", amsFeature, 2},
{"abilityms", amsFeature, 2},
{"bundlems", bmsFeature, 2}, // Add the policies configured for the two features in [Step 1](#li15901515152517) to the global policy settings.
{"bundlems", bmsFeature, 2}, // Add the policies configured for the two features in Step 1 to the global policy settings.
{"dtbschedsrv", dmsFeature, 1},
{"dtbschedsrv", dmsFeature, 1},
{"samgr", samgrFeature, 1},
{"samgr", samgrFeature, 1},
{"appspawn", appspawnFeature, 1},
{"appspawn", appspawnFeature, 1},
...
@@ -97,7 +97,7 @@ This section uses BMS as an example to describe how to configure access policies
...
@@ -97,7 +97,7 @@ This section uses BMS as an example to describe how to configure access policies
};
};
```
```
3. Register the **BmsFeature** defined in [Step 1](#li15901515152517) with Samgr.
3. Register the **BmsFeature** defined in [Step 1](#li15901515152517) with Samgr.
```
```
const char BMS_SERVICE[] = "bundlems";
const char BMS_SERVICE[] = "bundlems";
...
@@ -118,22 +118,22 @@ This section uses BMS as an example to describe how to configure access policies
...
@@ -118,22 +118,22 @@ This section uses BMS as an example to describe how to configure access policies
```
```
When you register a service with Samgr, Samgr calls the **GetCommunicationStrategy** function of the IPC authentication component to obtain access policies of the service. When other services or applications access this service through IPC, Samgr calls the **IsCommunicationAllowed** function of the IPC authentication component to check whether the services or applications have the access permission.
When you register a service with Samgr, Samgr calls the **GetCommunicationStrategy** function of the IPC authentication component to obtain access policies of the service. When other processes access this service through IPC, Samgr calls the **IsCommunicationAllowed** function of the IPC authentication component to check whether the processes have the access permission.
## FAQ<a name="section15729104510271"></a>
## FAQ<a name="section15729104510271"></a>
- Service registration failure
- Service registration failure
**Problem**
**Symptom**
During the startup of a new service, a message is displayed indicating that the service fails to be registered with Samgr.
During the startup of a new service, a message is displayed indicating that the service fails to be registered with Samgr.
**Cause**
**Possible Causes**
The service UID is not configured in the IPC authentication component.
The service UID is not configured in the IPC authentication component.
**Solution**
**Solutions**
Configure a valid UID for the service in the **base/security/permission/services/permission\_lite/ipc\_auth/src/ipc\_auth\_impl.c** file.
Configure the service UID in the **base/security/permission/services/permission\_lite/ipc\_auth/src/ipc\_auth\_impl.c** file.