!8106 Remove RPC Permission when client died

Merge pull request !8106 from Zhangzi/master
This commit is contained in:
openharmony_ci 2024-10-22 10:09:27 +00:00 committed by Gitee
commit 7d7664c681
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 21 additions and 14 deletions

View File

@ -401,7 +401,7 @@ static int32_t CheckPermissionAppInfo(const SoftBusPermissionEntry *pe,
return SOFTBUS_PERMISSION_DENIED;
}
static bool CheckDBinder(const char *sessionName)
bool CheckDBinder(const char *sessionName)
{
if (StrIsEmpty(sessionName)) {
return false;
@ -471,7 +471,7 @@ int32_t LoadPermissionJson(const char *fileName)
g_permissionEntryList->cnt++;
}
}
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
cJSON_Delete(jsonArray);
return SOFTBUS_OK;
}
@ -497,7 +497,7 @@ void DeinitPermissionJson(void)
while (!IsListEmpty(&g_permissionEntryList->list)) {
SoftBusPermissionEntry *item = LIST_ENTRY((&g_permissionEntryList->list)->next, SoftBusPermissionEntry, node);
if (item == NULL) {
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
COMM_LOGE(COMM_PERM, "get item is NULL");
return;
}
@ -505,7 +505,7 @@ void DeinitPermissionJson(void)
ListDelete(&item->node);
SoftBusFree(item);
}
SoftBusMutexUnlock(&g_permissionEntryList->lock);
(void)SoftBusMutexUnlock(&g_permissionEntryList->lock);
DestroySoftBusList(g_permissionEntryList);
g_permissionEntryList = NULL;
}
@ -710,20 +710,20 @@ int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char
SoftBusMutexLock(&g_dynamicPermissionList->lock);
if (g_dynamicPermissionList->cnt >= DYNAMIC_PERMISSION_MAX_SIZE) {
COMM_LOGE(COMM_PERM, "dynamic permission reach the upper limit");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_NO_ENOUGH_DATA;
}
if (HaveGrantedPermission(sessionName)) {
COMM_LOGD(COMM_PERM, "dynamic permission already granted");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
SoftBusPermissionEntry *permissionEntry = (SoftBusPermissionEntry *)SoftBusCalloc(sizeof(SoftBusPermissionEntry));
if (permissionEntry == NULL) {
COMM_LOGE(COMM_PERM, "AddDynamicPermission malloc failed!");
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_MALLOC_ERR;
}
@ -731,18 +731,19 @@ int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char
if (ret != SOFTBUS_OK) {
COMM_LOGE(COMM_PERM, "NewDynamicPermissionEntry failed. ret=%{public}d", ret);
SoftBusFree(permissionEntry);
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return ret;
}
ListNodeInsert(&g_dynamicPermissionList->list, &permissionEntry->node);
g_dynamicPermissionList->cnt++;
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
COMM_LOGD(COMM_PERM, "session dynamic permission granted. sessionName=%{public}s", AnonymizeWrapper(tmpName));
COMM_LOGD(COMM_PERM, "session dynamic permission granted. sessionName=%{public}s, count=%{public}d",
AnonymizeWrapper(tmpName), g_dynamicPermissionList->cnt);
AnonymizeFree(tmpName);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
@ -760,15 +761,15 @@ int32_t DeleteDynamicPermission(const char *sessionName)
ListDelete(&pe->node);
SoftBusFree(pe);
g_dynamicPermissionList->cnt--;
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
char *tmpName = NULL;
Anonymize(sessionName, &tmpName);
COMM_LOGI(COMM_PERM, "session dynamic permission deleted. sessionName=%{public}s",
AnonymizeWrapper(tmpName));
COMM_LOGI(COMM_PERM, "session dynamic permission deleted. sessionName=%{public}s, count=%{public}d",
AnonymizeWrapper(tmpName), g_dynamicPermissionList->cnt);
AnonymizeFree(tmpName);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_OK;
}
}
SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
(void)SoftBusMutexUnlock(&g_dynamicPermissionList->lock);
return SOFTBUS_NOT_FIND;
}

View File

@ -75,6 +75,7 @@ int32_t InitDynamicPermission(void);
int32_t AddDynamicPermission(int32_t callingUid, int32_t callingPid, const char *sessionName);
int32_t DeleteDynamicPermission(const char *sessionName);
int32_t CompareString(const char *src, const char *dest, bool regexp);
bool CheckDBinder(const char *sessionName);
#ifdef __cplusplus
#if __cplusplus

View File

@ -17,6 +17,7 @@
#include "anonymizer.h"
#include "lnn_lane_link.h"
#include "permission_entry.h"
#include "securec.h"
#include "softbus_adapter_mem.h"
#include "softbus_adapter_thread.h"
@ -255,6 +256,10 @@ void TransDelItemByPackageName(const char *pkgName, int32_t pid)
}
LIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &g_sessionServerList->list, SessionServer, node) {
if ((strcmp(pos->pkgName, pkgName) == 0) && (pos->pid == pid)) {
if (CheckDBinder(pos->sessionName)) {
// Remove RPC Permission when Client Process Exit
(void)DeleteDynamicPermission(pos->sessionName);
}
ListDelete(&pos->node);
g_sessionServerList->cnt--;
SoftBusFree(pos);