| 167 | } |
| 168 | |
| 169 | static void createUser(const String & user_name, [[maybe_unused]] const String & group_name) |
| 170 | { |
| 171 | if (!user_name.empty()) |
| 172 | { |
| 173 | #if defined(OS_DARWIN) |
| 174 | // TODO: implement. |
| 175 | throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Unable to create a user in macOS"); |
| 176 | #elif defined(OS_FREEBSD) |
| 177 | std::string command = group_name.empty() |
| 178 | ? fmt::format("pw useradd -s /bin/false -d /nonexistent -n {}", shellQuote(user_name)) |
| 179 | : fmt::format("pw useradd -s /bin/false -d /nonexistent -g {} -n {}", shellQuote(group_name), shellQuote(user_name)); |
| 180 | fmt::print(" {}\n", command); |
| 181 | executeScript(command); |
| 182 | #else |
| 183 | std::string command = group_name.empty() |
| 184 | ? fmt::format("useradd -r --shell /bin/false --home-dir /nonexistent --user-group {}", shellQuote(user_name)) |
| 185 | : fmt::format("useradd -r --shell /bin/false --home-dir /nonexistent -g {} {}", shellQuote(group_name), shellQuote(user_name)); |
| 186 | fmt::print(" {}\n", command); |
| 187 | executeScript(command); |
| 188 | #endif |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | |
| 193 | static std::string formatWithSudo(std::string command, bool needed = true) |
no test coverage detected