diff --git a/src/pk11.cc b/src/pk11.cc index d5088b1..bbba0ee 100644 --- a/src/pk11.cc +++ b/src/pk11.cc @@ -29,9 +29,13 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include #include"tss/tspi.h" @@ -94,9 +98,17 @@ Config get_config() { const char* home{getenv("HOME")}; + if (home == nullptr) { + struct passwd *pwd = getpwuid(getuid()); + if (pwd == NULL) { + throw std::system_error(std::error_code(errno, std::system_category()), + std::string(__func__) + "(): getpwuid."); + } + home = pwd->pw_dir; + } if (home == nullptr) { throw std::runtime_error(std::string(__func__) + "(): " - + "getenv(HOME) failed."); + + "could not get HOME of user by ENV or via passwd."); } std::string config_path{std::string{home} + "/" + config_dir + "/config"};