From 02c8544121d78ce884bdcb7abfc17f25387989b2 Mon Sep 17 00:00:00 2001 From: zhong_ning Date: Thu, 12 Aug 2021 10:10:14 +0800 Subject: [PATCH] modify setgid Signed-off-by: zhong_ning --- services/src/init_service.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/services/src/init_service.c b/services/src/init_service.c index 2c014b1c4..239c2b510 100644 --- a/services/src/init_service.c +++ b/services/src/init_service.c @@ -78,11 +78,15 @@ static int SetPerms(const Service *service) return SERVICE_FAILURE; } - if (setgroups(service->servPerm.gIDCnt, service->servPerm.gIDArray) != 0) { - INIT_LOGE("SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt); - return SERVICE_FAILURE; + if (service->servPerm.gIDCnt > 0) { + INIT_ERROR_CHECK(setgid(service->servPerm.gIDArray[0]) == 0, return SERVICE_FAILURE, + "SetPerms, setgid for %s failed. %d", service->name, errno); + } + if (service->servPerm.gIDCnt > 1) { + INIT_ERROR_CHECK(setgroups(service->servPerm.gIDCnt - 1, &service->servPerm.gIDArray[1]) == 0, + return SERVICE_FAILURE, + "SetPerms, setgroups failed. errno = %d, gIDCnt=%d", errno, service->servPerm.gIDCnt); } - if (service->servPerm.uID != 0) { if (setuid(service->servPerm.uID) != 0) { INIT_LOGE("setuid of service: %s failed, uid = %d", service->name, service->servPerm.uID); -- Gitee