diff --git a/samgr_endpoint/source/sa_store.c b/samgr_endpoint/source/sa_store.c index c3731e0..b9dd423 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 762badf..d249281 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 b564136..107dd0b 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);