diff --git a/samgr_endpoint/source/sa_store.c b/samgr_endpoint/source/sa_store.c index c3731e0ceabb5878806dc133bf0b29a9b3d99b57..b9dd4230791f7483b2fd2c4c92e492642f790df5 100755 --- a/samgr_endpoint/source/sa_store.c +++ b/samgr_endpoint/source/sa_store.c @@ -162,6 +162,29 @@ int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handl return INVALID_INDEX; } +int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle) +{ + if (saStore == NULL || saStore->maps == NULL || handle == NULL) { + return INVALID_INDEX; + } + int16 high = saStore->mapTop - 1; + int16 low = 0; + while (low <= high) { + // binary search need div 2 + int16 mid = (high + low) / 2; + if (saStore->maps[mid].pid == callingPid && saStore->maps[mid].uid == callingUid) { + *handle = saStore->maps[mid]; + return mid; + } + if (saStore->maps[mid].pid < callingPid) { + low = mid + 1; + continue; + } + high = mid - 1; + } + return INVALID_INDEX; +} + PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle) { PidHandle pidHandle = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX}; diff --git a/samgr_endpoint/source/sa_store.h b/samgr_endpoint/source/sa_store.h index 762badfebe11de4227f6f2f28d2483eeb5bf7f8d..d2492817f4c2d5ac486a9541f40e1306c10f46e6 100755 --- a/samgr_endpoint/source/sa_store.h +++ b/samgr_endpoint/source/sa_store.h @@ -75,6 +75,7 @@ static inline void SASTORA_Init(SAStore *saStore) int SASTORA_Save(SAStore *saStore, const char *service, const char *feature, const SvcIdentity *identity); int SASTORA_SaveHandleByPid(SAStore *saStore, PidHandle handle); int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handle); +int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle); SvcIdentity SASTORA_Find(SAStore *saStore, const char *service, const char *feature); int SASTORA_ClearByPid(SAStore *saStore, pid_t pid); PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle); diff --git a/samgr_server/source/samgr_server.c b/samgr_server/source/samgr_server.c index b564136dc5d01871fa0e39d2f44984c374fe3a9f..107dd0b2c2a9647c2b5e1e524f51bc494c12fb83 100755 --- a/samgr_server/source/samgr_server.c +++ b/samgr_server/source/samgr_server.c @@ -194,10 +194,11 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req, return EC_INVALID; } pid_t pid = GetCallingPid(origin); + uid_t uid = GetCallingUid(origin); char *feature = IpcIoPopBool(req) ? NULL : (char *)IpcIoPopString(req, &len); MUTEX_Lock(server->mtx); PidHandle handle; - int index = SASTORA_FindHandleByPid(&server->store, pid, &handle); + int index = SASTORA_FindHandleByUidPid(&server->store, uid, pid, &handle); if (index == INVALID_INDEX) { MUTEX_Unlock(server->mtx); HILOG_ERROR(HILOG_MODULE_SAMGR, "Endpoint[%d] is not register", pid);