| 18 | namespace |
| 19 | { |
| 20 | std::string getUserName(uid_t user_id) |
| 21 | { |
| 22 | /// Try to convert user id into user name. |
| 23 | auto buffer_size = sysconf(_SC_GETPW_R_SIZE_MAX); |
| 24 | if (buffer_size <= 0) |
| 25 | buffer_size = 1024; |
| 26 | std::string buffer; |
| 27 | buffer.reserve(buffer_size); |
| 28 | |
| 29 | struct passwd passwd_entry{}; |
| 30 | struct passwd * result = nullptr; |
| 31 | const auto error = getpwuid_r(user_id, &passwd_entry, buffer.data(), buffer_size, &result); |
| 32 | |
| 33 | if (error) |
| 34 | ErrnoException::throwWithErrno( |
| 35 | ErrorCodes::FAILED_TO_GETPWUID, error, "Failed to find user name for {}", std::to_string(user_id)); |
| 36 | else if (result) |
| 37 | return result->pw_name; |
| 38 | return std::to_string(user_id); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void assertProcessUserMatchesDataOwner(const std::string & path, std::function<void(const PreformattedMessage &)> on_warning) |
no test coverage detected