2024-02-05 22:25:30 -08:00
|
|
|
#include "ehs/system/User.h"
|
|
|
|
#include "ehs/Log.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cerrno>
|
|
|
|
|
|
|
|
namespace ehs
|
|
|
|
{
|
|
|
|
void User::GetId(UInt_32* const real, UInt_32* const effective, UInt_32* const saved)
|
|
|
|
{
|
|
|
|
if (getresuid(real, effective, saved) == -1)
|
2024-04-23 22:29:49 -07:00
|
|
|
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
2024-02-05 22:25:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Str_8 User::GetName()
|
|
|
|
{
|
|
|
|
SInt_64 max = sysconf(_SC_LOGIN_NAME_MAX);
|
|
|
|
if (max == -1)
|
|
|
|
{
|
2024-04-23 22:29:49 -07:00
|
|
|
EHS_LOG_INT(LogType::ERR, 0, strerror(errno));
|
2024-02-05 22:25:30 -08:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Char_8* name = new Char_8[max];
|
|
|
|
|
|
|
|
if (getlogin_r(name, max) == -1)
|
|
|
|
{
|
|
|
|
delete[] name;
|
2024-04-23 22:29:49 -07:00
|
|
|
EHS_LOG_INT(LogType::ERR, 1, strerror(errno));
|
2024-02-05 22:25:30 -08:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Str_8 result(name);
|
|
|
|
|
|
|
|
delete[] name;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|