e = MAX_GETPW_R_BUF_SIZE; ++ } ++ ++ for (const auto& [uid, groups] : usersGroups) ++ { ++ nlohmann::json groupNames = nlohmann::json::array(); ++ ++ for (const auto& gid : groups) ++ { ++ struct group grp; ++ struct group* grpResult = nullptr; ++ auto groupBuf = std::make_unique(bufSize); ++ ++ if (m_groupWrapper->getgrgid_r(gid, &grp, groupBuf.get(), bufSize, &grpResult) == 0 && grpResult != nullptr) ++ { ++ groupNames.push_back(grpResult->gr_name); ++ } ++ } ++ ++ if (singleUid) ++ { ++ result = groupNames; ++ } ++ else ++ { ++ result[std::to_string(uid)] = groupNames; ++ } ++ } ++ ++ return result; ++} ++ ++nlohmann::json UserGroupsProvider::getUserNamesByGid(const std::set& gids) ++{ ++ const bool allGroups = gids.empty(); ++ const bool singleGid = (!allGroups && gids.size() == 1); ++ nlohmann::json result = singleGid ? nlohmann::json::array() : nlohmann::json::object(); ++ ++ size_t bufSize = sysconf(_SC_GETPW_R_SIZE_MAX); ++ ++ if (bufSize > MAX_GETPW_R_BUF_SIZE) ++ { ++ bufSize = MAX_GETPW_R_BUF_SIZE; ++ } ++ ++ std::map> gidToUsernames; ++ ++ if (allGroups) ++ { ++ struct group* grp = nullptr; ++ m_groupWrapper->setgrent(); ++ ++ while ((grp = m_groupWrapper->getgrent()) != nullptr) ++ { ++ gid_t gid = grp->gr_gid; ++ char** members = grp->gr_mem; ++ ++ while (members && *members) ++ { ++ gidToUsernames[gid].insert(*members); ++ ++members; ++ } ++ } ++ ++ m_groupWrapper->endgrent(); ++ } ++ else ++ { ++ for (const auto& gid : gids) ++ { ++ struct group grp; ++ struct group* grpResult = nullptr; ++ auto groupBuf = std::make_unique(bufSize); *** 863 LINES SKIPPED ***