in common/util.hpp [933:984]
static std::pair<int, std::string> get_machine_principal( std::string domain_name,
CF_logger& cf_logger )
{
std::pair<int, std::string> result = std::make_pair( -1, "" );
char hostname[HOST_NAME_MAX];
int status = gethostname( hostname, HOST_NAME_MAX );
if ( status )
{
result.first = status;
return result;
}
std::pair<int, std::string> realm_name_result = Util::get_realm_name();
if ( realm_name_result.first != 0 )
{
return realm_name_result;
}
std::pair<int, std::string> domain_name_result = Util::check_domain_name( domain_name );
if ( domain_name_result.first != 0 )
{
return domain_name_result;
}
std::string s = std::string( hostname );
std::string host_name = s.substr( 0, s.find( '.' ) );
// truncate the hostname to the host name size limit defined by microsoft
if ( host_name.length() > HOST_NAME_LENGTH_LIMIT )
{
std::string log_message = "WARNING: " + std::string( __func__ ) + " : " +
std::to_string( __LINE__ ) +
" hostname exceeds 15 characters, this can cause problems in "
"getting kerberos tickets, please reduce hostname length";
cf_logger.logger( LOG_ERR, log_message.c_str() );
host_name = host_name.substr( 0, HOST_NAME_LENGTH_LIMIT );
std::cerr << Util::getCurrentTime() << '\t'
<< "INFO: hostname exceeds 15 characters this can "
"cause problems in getting kerberos tickets, "
"please reduce hostname length"
<< std::endl;
}
/**
* Machine principal is of the format EC2AMAZ-Q5VJZQ$@CONTOSO.COM'
*/
result.first = 0;
result.second = "'" + host_name + "$@'" + realm_name_result.second;
return result;
}