From eb971473a27489aab96871f24295243b1843a0f0 Mon Sep 17 00:00:00 2001 From: zjucx Date: Fri, 19 Mar 2021 09:52:26 +0800 Subject: [PATCH 1/4] update samgr/source/message.c. --- samgr/source/message.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/samgr/source/message.c b/samgr/source/message.c index 5fd8500..3c31c27 100755 --- a/samgr/source/message.c +++ b/samgr/source/message.c @@ -27,7 +27,7 @@ #define DONT_WAIT 0 #define WAIT_FOREVER (-1) -static int32 SharedSend(MQueueId queueId, Exchange *exchange); +static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef); static BOOL FreeReference(Exchange *exchange); int32 SAMGR_SendRequest(const Identity *identity, const Request *request, Handler handler) @@ -54,7 +54,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response) } Exchange *exchange = GET_OBJECT(request, Exchange, request); - if (exchange->type == MSG_NON) { + if (exchange->type != MSG_CON) { return EC_INVALID; } @@ -76,7 +76,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response) } // Send back to the origin to process the task. - int32 ret = SharedSend(exchange->id.queueId, exchange); + int32 ret = SharedSend(exchange->id.queueId, exchange, 1); if (ret != EC_SUCCESS) { exchange->handler(&exchange->request, &exchange->response); (void)FreeReference(exchange); @@ -123,7 +123,7 @@ uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request Exchange exchange = {*identity, *request, {NULL, 0}, MSG_NON, handler, token}; exchange.type = (handler == NULL) ? MSG_NON : MSG_CON; exchange.id.queueId = NULL; - int32 err = SharedSend(identity->queueId, &exchange); + int32 err = SharedSend(identity->queueId, &exchange, 0); if (err != EC_SUCCESS) { HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err); (void)FreeReference(&exchange); @@ -152,7 +152,7 @@ int32 SAMGR_SendSharedDirectRequest(const Identity *id, const Request *req, cons exchange.type = MSG_DIRECT; exchange.id = *id; exchange.id.queueId = NULL; - int32 err = SharedSend(id->queueId, &exchange); + int32 err = SharedSend(id->queueId, &exchange, 0); if (err != EC_SUCCESS) { HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", id->queueId, err); (void)FreeReference(&exchange); @@ -177,7 +177,7 @@ int32 SAMGR_SendResponseByIdentity(const Identity *id, const Request *request, c return SAMGR_SendResponse(request, response); } -static int32 SharedSend(MQueueId queueId, Exchange *exchange) +static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef) { /* if the msg data and response is NULL, we just direct copy, no need shared the message. */ if ((exchange->request.data == NULL || exchange->request.len <= 0) && @@ -188,12 +188,12 @@ static int32 SharedSend(MQueueId queueId, Exchange *exchange) /* 1.add reference */ MUTEX_GlobalLock(); if (exchange->sharedRef == NULL) { - exchange->sharedRef = (uint32 *)SAMGR_Malloc(sizeof(uint32)); + exchange->sharedRef = (uint32*)SAMGR_Malloc(sizeof(uint32)); if (exchange->sharedRef == NULL) { MUTEX_GlobalUnlock(); return EC_NOMEMORY; } - *(exchange->sharedRef) = 0; + *(exchange->sharedRef) = initRef; } (*(exchange->sharedRef))++; MUTEX_GlobalUnlock(); -- Gitee From 4df2ee200c3ee9c8250f39a14dd8643d8884dc03 Mon Sep 17 00:00:00 2001 From: zjucx Date: Tue, 8 Jun 2021 11:13:56 +0800 Subject: [PATCH 2/4] update interfaces/kits/registry/iproxy_client.h. --- interfaces/kits/registry/iproxy_client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/registry/iproxy_client.h b/interfaces/kits/registry/iproxy_client.h index 302a675..19ec48e 100755 --- a/interfaces/kits/registry/iproxy_client.h +++ b/interfaces/kits/registry/iproxy_client.h @@ -52,7 +52,7 @@ extern "C" { #endif #endif -#define CLIENT_PROXY_VER 0x40 +#define CLIENT_PROXY_VER (0x40 | (uint16)DEFAULT_VERSION) /** * @brief Indicates the inherited macro of the client proxy. -- Gitee From be9baf52ca49b06b1916ce1b442fd21f6ed17f8b Mon Sep 17 00:00:00 2001 From: zjucx Date: Fri, 25 Jun 2021 06:17:35 +0000 Subject: [PATCH 3/4] modify 404 error --- README.md | 4 ++-- README_zh.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8b4fda..87f6aa0 100755 --- a/README.md +++ b/README.md @@ -627,7 +627,7 @@ Main objects of the SA framework: ## Repositories Involved -[Distributed Scheduler subsystem](en-us_topic_0000001115719369.md) +Distributed Scheduler subsystem -**[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite)** +**samgr\_lite** diff --git a/README_zh.md b/README_zh.md index be87849..9e14fd1 100755 --- a/README_zh.md +++ b/README_zh.md @@ -627,7 +627,7 @@ ## 涉及仓 -**[分布式任务调度子系统](zh-cn_topic_0000001115719369.md)** +分布式任务调度子系统 -[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite) +**samgr\_lite** -- Gitee From e41b760ebd6deda06986f3471a6085d5fff277ad Mon Sep 17 00:00:00 2001 From: zjucx Date: Fri, 2 Jul 2021 17:05:01 +0800 Subject: [PATCH 4/4] add uid verify for ProcPutFeature --- samgr_endpoint/source/sa_store.c | 23 +++++++++++++++++++++++ samgr_endpoint/source/sa_store.h | 1 + samgr_server/source/samgr_server.c | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) 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); -- Gitee