Merge pull request #16 from open-amt-cloud-toolkit/fqdn
Add/update DNS Suffix (OS), Hostname (OS), fqdn [AMT] and DNS Suffix …
This commit is contained in:
@@ -126,23 +126,21 @@ add_dependencies(rpc MicroLMS )
|
||||
|
||||
target_link_libraries (rpc PRIVATE
|
||||
MicroLMS
|
||||
iphlpapi
|
||||
cpprestsdk::cpprest
|
||||
cpprestsdk::cpprestsdk_zlib_internal
|
||||
cpprestsdk::cpprestsdk_boost_internal
|
||||
cpprestsdk::cpprestsdk_brotli_internal
|
||||
${Boost_LIBRARIES}
|
||||
DbgHelp.lib
|
||||
Iphlpapi.lib
|
||||
Setupapi.lib
|
||||
ws2_32.lib
|
||||
Psapi.lib
|
||||
Crypt32.lib
|
||||
Wintrust.lib
|
||||
Version.lib
|
||||
Wtsapi32.lib
|
||||
Gdiplus.lib
|
||||
Userenv.lib
|
||||
Iphlpapi.lib
|
||||
Setupapi.lib
|
||||
ws2_32.lib
|
||||
Psapi.lib
|
||||
Crypt32.lib
|
||||
Wintrust.lib
|
||||
Version.lib
|
||||
Wtsapi32.lib
|
||||
Gdiplus.lib
|
||||
Userenv.lib
|
||||
)
|
||||
|
||||
endif (UNIX)
|
||||
|
@@ -147,6 +147,10 @@ const PTHI_MESSAGE_HEADER SET_HOST_FQDN_HEADER = {
|
||||
{AMT_MAJOR_VERSION, AMT_MAJOR_VERSION}, 0, {{SET_HOST_FQDN_REQUEST}}, 0
|
||||
};
|
||||
|
||||
const PTHI_MESSAGE_HEADER GET_FQDN_HEADER = {
|
||||
{AMT_MAJOR_VERSION, AMT_MAJOR_VERSION}, 0, {{GET_FQDN_REQUEST}}, 0
|
||||
};
|
||||
|
||||
const PTHI_MESSAGE_HEADER GET_LOCAL_SYSTEM_ACCOUNT_HEADER = {
|
||||
{AMT_MAJOR_VERSION, AMT_MINOR_VERSION}, 0, {{GET_LOCAL_SYSTEM_ACCOUNT_REQUEST}}, 40
|
||||
};
|
||||
@@ -202,10 +206,7 @@ AMT_STATUS _call(const unsigned char *command, UINT32 command_size, UINT8 **read
|
||||
{
|
||||
return status;
|
||||
}
|
||||
if ((expSize != 0) && (expSize != outBuffSize))
|
||||
{
|
||||
return PTSDK_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
return AMT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1359,6 +1360,54 @@ AMT_STATUS pthi_SetHostFQDN(char* str)
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets host FQDN in AMT Calls to CFG_SET_HOST_FQDN_REQUEST command
|
||||
* Arguments:
|
||||
* host - host FQDN
|
||||
* Return values:
|
||||
* AMT_STATUS_SUCCESS - on success
|
||||
* PTSDK_STATUS_INTERNAL_ERROR - on failure
|
||||
*/
|
||||
AMT_STATUS pthi_GetHostFQDN(CFG_GET_FQDN_RESPONSE* fqdn)
|
||||
{
|
||||
AMT_STATUS status;
|
||||
UINT8* readBuffer = NULL;
|
||||
UINT32 command_size = sizeof(CFG_GET_HOST_FQDN_REQUEST);
|
||||
CFG_GET_HOST_FQDN_REQUEST command;
|
||||
CFG_GET_FQDN_RESPONSE* tmp_response;
|
||||
|
||||
memset(&command, 0, sizeof(CFG_GET_HOST_FQDN_REQUEST));
|
||||
memcpy_s((UINT8*)&command, sizeof(command), (char*)&(GET_FQDN_HEADER), sizeof(GET_FQDN_HEADER));
|
||||
status = _call((UINT8*)&command, command_size, &readBuffer, GET_FQDN_RESPONSE, sizeof(CFG_GET_FQDN_RESPONSE) - sizeof(char *));
|
||||
|
||||
// tes
|
||||
if (status == AMT_STATUS_SUCCESS)
|
||||
{
|
||||
tmp_response = (CFG_GET_FQDN_RESPONSE*)readBuffer;
|
||||
memcpy_s(&(fqdn->Header), sizeof(PTHI_MESSAGE_HEADER), (char*)&(tmp_response->Header), sizeof(PTHI_MESSAGE_HEADER));
|
||||
fqdn->Status = tmp_response->Status;
|
||||
fqdn->SharedFQDN = tmp_response->SharedFQDN;
|
||||
fqdn->DDNSUpdateEnabled = tmp_response->DDNSUpdateEnabled;
|
||||
fqdn->DDNSPeriodicUpdateInterval = tmp_response->DDNSPeriodicUpdateInterval;
|
||||
fqdn->DDNSTTL = tmp_response->DDNSTTL;
|
||||
|
||||
fqdn->FQDN.Length = tmp_response->FQDN.Length;
|
||||
fqdn->FQDN.Buffer = (CHAR*)malloc(fqdn->FQDN.Length * sizeof(CHAR));
|
||||
if (NULL == fqdn->FQDN.Buffer) {
|
||||
status = AMT_STATUS_INTERNAL_ERROR;
|
||||
}
|
||||
else {
|
||||
memcpy_s(fqdn->FQDN.Buffer,
|
||||
fqdn->FQDN.Length * sizeof(CHAR),
|
||||
&(tmp_response->FQDN.Buffer),
|
||||
tmp_response->FQDN.Length * sizeof(CHAR));
|
||||
}
|
||||
}
|
||||
if (readBuffer != NULL) free(readBuffer);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
@@ -509,6 +509,18 @@ typedef struct _AMT_PROV_AUDIT_RECORD
|
||||
AMT_ANSI_STRING ProvServerFQDN;
|
||||
} AMT_PROV_AUDIT_RECORD;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PTHI_MESSAGE_HEADER Header;
|
||||
AMT_STATUS Status;
|
||||
AMT_BOOLEAN SharedFQDN;
|
||||
AMT_BOOLEAN DDNSUpdateEnabled;
|
||||
UINT32 DDNSPeriodicUpdateInterval;
|
||||
UINT32 DDNSTTL;
|
||||
UINT32 HostNameLength;
|
||||
AMT_ANSI_STRING FQDN;
|
||||
} CFG_GET_FQDN_RESPONSE;
|
||||
|
||||
typedef struct _CFG_GENERATE_RNG_SEED_RESPONSE
|
||||
{
|
||||
PTHI_RESPONSE_MESSAGE_HEADER Header;
|
||||
@@ -583,6 +595,11 @@ typedef struct CFG_SET_HOST_FQDN_REQUEST
|
||||
char FQDN[256];
|
||||
}CFG_SET_HOST_FQDN_REQUEST;
|
||||
|
||||
typedef struct CFG_GET_HOST_FQDN_REQUEST
|
||||
{
|
||||
PTHI_MESSAGE_HEADER Header;
|
||||
} CFG_GET_HOST_FQDN_REQUEST;
|
||||
|
||||
typedef struct _CFG_SET_HOST_FQDN_RESPONSE
|
||||
{
|
||||
PTHI_MESSAGE_HEADER Header;
|
||||
@@ -678,6 +695,7 @@ AMT_STATUS pthi_EnumerateHashHandles(AMT_HASH_HANDLES *hashHandles);
|
||||
AMT_STATUS pthi_GetCertificateHashEntry(UINT32 hashHandle, CERTHASH_ENTRY *hashEntry);
|
||||
AMT_STATUS pthi_GetDnsSuffix(AMT_ANSI_STRING *dnsSuffix);
|
||||
AMT_STATUS pthi_SetHostFQDN(char* str);
|
||||
AMT_STATUS pthi_GetHostFQDN(CFG_GET_FQDN_RESPONSE* fqdn);
|
||||
AMT_STATUS pthi_GetLocalSystemAccount(LOCAL_SYSTEM_ACCOUNT *localAccount);
|
||||
AMT_STATUS pthi_Unprovision(CFG_PROVISIONING_MODE provisionMode);
|
||||
AMT_STATUS pthi_GetStateEHBC(AMT_EHBC_STATE *state);
|
||||
@@ -790,6 +808,10 @@ const PTHI_MESSAGE_HEADER GET_FEATURES_STATE_HEADER;
|
||||
#define SET_HOST_FQDN_RESPONSE 0x0480005b
|
||||
//const PTHI_MESSAGE_HEADER GET_PKI_FQDN_SUFFIX_HEADER;
|
||||
|
||||
#define GET_FQDN_REQUEST 0x4000056
|
||||
#define GET_FQDN_RESPONSE 0x4800056
|
||||
|
||||
|
||||
#define GET_LOCAL_SYSTEM_ACCOUNT_REQUEST 0x04000067
|
||||
#define GET_LOCAL_SYSTEM_ACCOUNT_RESPONSE 0x04800067
|
||||
//const PTHI_MESSAGE_HEADER GET_LOCAL_SYSTEM_ACCOUNT_HEADER;
|
||||
|
@@ -60,22 +60,8 @@ std::string get_dns_info()
|
||||
|
||||
if (!dnsSuffix.length())
|
||||
{
|
||||
std::vector<unsigned char> address;
|
||||
cmd_get_wired_mac_address(address);
|
||||
|
||||
if (address.size() == 6)
|
||||
{
|
||||
char macAddress[6];
|
||||
macAddress[0] = address[0];
|
||||
macAddress[1] = address[1];
|
||||
macAddress[2] = address[2];
|
||||
macAddress[3] = address[3];
|
||||
macAddress[4] = address[4];
|
||||
macAddress[5] = address[5];
|
||||
|
||||
// get DNS from OS
|
||||
dnsSuffix = net_get_dns(macAddress);
|
||||
}
|
||||
// get DNS from OS
|
||||
dnsSuffix = net_get_dns();
|
||||
}
|
||||
|
||||
return dnsSuffix;
|
||||
|
30
commands.cpp
30
commands.cpp
@@ -179,6 +179,36 @@ bool cmd_get_control_mode(int& mode)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cmd_get_fqdn(fqdn_settings& fqdn_settings)
|
||||
{
|
||||
fqdn_settings.fqdn.clear();
|
||||
|
||||
// initialize HECI interface
|
||||
if (heci_Init(NULL, PTHI_CLIENT) == 0) return false;
|
||||
|
||||
// get fqdn
|
||||
CFG_GET_FQDN_RESPONSE fqdn;
|
||||
memset(&fqdn, 0, sizeof(CFG_GET_FQDN_RESPONSE));
|
||||
AMT_STATUS amt_status = pthi_GetHostFQDN(&fqdn);
|
||||
|
||||
if (amt_status == 0)
|
||||
{
|
||||
fqdn_settings.ddns_ttl = fqdn.DDNSTTL;
|
||||
fqdn_settings.ddns_update_enabled = fqdn.DDNSUpdateEnabled;
|
||||
fqdn_settings.ddns_update_interval = fqdn.DDNSPeriodicUpdateInterval;
|
||||
|
||||
if (fqdn.FQDN.Length > 0)
|
||||
{
|
||||
fqdn_settings.fqdn = std::string(fqdn.FQDN.Buffer, fqdn.FQDN.Length);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool cmd_get_dns_suffix(std::string& suffix)
|
||||
{
|
||||
suffix.clear();
|
||||
|
10
commands.h
10
commands.h
@@ -28,6 +28,15 @@ struct lan_interface_settings
|
||||
std::vector<unsigned char> mac_address;
|
||||
};
|
||||
|
||||
struct fqdn_settings
|
||||
{
|
||||
bool shared_fqdn;
|
||||
bool ddns_update_enabled;
|
||||
int ddns_update_interval;
|
||||
int ddns_ttl;
|
||||
std::string fqdn;
|
||||
};
|
||||
|
||||
bool cmd_is_admin();
|
||||
bool cmd_get_version(std::string& version);
|
||||
bool cmd_get_build_number(std::string& version);
|
||||
@@ -35,6 +44,7 @@ bool cmd_get_sku(std::string& version);
|
||||
bool cmd_get_uuid(std::vector<unsigned char>& uuid);
|
||||
bool cmd_get_local_system_account(std::string& username, std::string& password);
|
||||
bool cmd_get_control_mode(int& mode);
|
||||
bool cmd_get_fqdn(fqdn_settings& fqdn_settings);
|
||||
bool cmd_get_dns_suffix(std::string& suffix);
|
||||
bool cmd_get_wired_mac_address(std::vector<unsigned char>& address);
|
||||
bool cmd_get_certificate_hashes(std::vector<cert_hash_entry>& hash_entries);
|
||||
|
39
info.cpp
39
info.cpp
@@ -9,6 +9,7 @@
|
||||
#include <iomanip>
|
||||
#include "commands.h"
|
||||
#include "utils.h"
|
||||
#include "network.h"
|
||||
|
||||
const int PADDING = 25;
|
||||
|
||||
@@ -124,6 +125,29 @@ bool info_get_dns_suffix()
|
||||
|
||||
out_text("DNS Suffix", tmp);
|
||||
|
||||
|
||||
tmp = net_get_dns();
|
||||
out_text("DNS Suffix (OS)", tmp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool info_get_fqdn()
|
||||
{
|
||||
fqdn_settings fqdn;
|
||||
|
||||
if (cmd_get_fqdn(fqdn))
|
||||
{
|
||||
out_text("FQDN", fqdn.fqdn);
|
||||
}
|
||||
|
||||
std::string tmp;
|
||||
std::string dns;
|
||||
|
||||
tmp = net_get_hostname();
|
||||
out_text("Hostname (OS)", tmp);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -159,12 +183,13 @@ bool info_get_all()
|
||||
bool status_uuid = info_get_uuid();
|
||||
bool status_mode = info_get_control_mode();
|
||||
bool status_dns = info_get_dns_suffix();
|
||||
bool status_fqdn = info_get_fqdn();
|
||||
bool status_ras = info_get_remote_access_connection_status();
|
||||
bool status_lan = info_get_lan_interface_settings();
|
||||
bool status_cert = info_get_certificate_hashes();
|
||||
|
||||
if (status_ver && status_bld && status_sku && status_uuid && status_mode &&
|
||||
status_dns && status_ras && status_lan && status_cert)
|
||||
status_dns && status_fqdn && status_ras && status_lan && status_cert)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -282,6 +307,10 @@ bool info_get(const std::string info)
|
||||
{
|
||||
return info_get_dns_suffix();
|
||||
}
|
||||
else if (info.compare("fqdn") == 0)
|
||||
{
|
||||
return info_get_fqdn();
|
||||
}
|
||||
else if (info.compare("cert") == 0)
|
||||
{
|
||||
return info_get_certificate_hashes();
|
||||
@@ -304,10 +333,10 @@ bool info_get(const std::string info)
|
||||
|
||||
bool info_get_verify(const std::string info)
|
||||
{
|
||||
if ((info.compare("ver") == 0) || (info.compare("bld") == 0) || (info.compare("sku") == 0) ||
|
||||
(info.compare("uuid") == 0) || (info.compare("mode") == 0) || (info.compare("dns") == 0) ||
|
||||
(info.compare("cert") == 0) || (info.compare("ras") == 0) || (info.compare("lan") == 0) ||
|
||||
(info.compare("all") == 0))
|
||||
if ((info.compare("ver") == 0) || (info.compare("bld") == 0) || (info.compare("sku") == 0) ||
|
||||
(info.compare("uuid") == 0) || (info.compare("mode") == 0) || (info.compare("fqdn") == 0) ||
|
||||
(info.compare("dns") == 0) || (info.compare("cert") == 0) || (info.compare("ras") == 0) ||
|
||||
(info.compare("lan") == 0) || (info.compare("all") == 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
1
info.h
1
info.h
@@ -16,6 +16,7 @@ bool info_get_sku();
|
||||
bool info_get_uuid();
|
||||
bool info_get_control_mode();
|
||||
bool info_get_dns_suffix();
|
||||
bool info_get_fqdn();
|
||||
bool info_get_all();
|
||||
bool info_get_remote_access_connection_status();
|
||||
bool info_get_lan_interface_settings();
|
||||
|
57
network.cpp
57
network.cpp
@@ -4,7 +4,9 @@
|
||||
**********************************************************************/
|
||||
|
||||
#include "network.h"
|
||||
#include "commands.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
@@ -181,5 +183,58 @@ std::string net_get_dns(char* macAddress)
|
||||
|
||||
return dnsSuffix;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
std::string net_get_hostname()
|
||||
{
|
||||
char hostname[256];
|
||||
std::string hostname_string = "";
|
||||
int result;
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA wsa;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsa) != 0)
|
||||
{
|
||||
throw std::runtime_error("error: network error");
|
||||
}
|
||||
#endif
|
||||
|
||||
// get hostname
|
||||
result = gethostname(hostname, sizeof(hostname));
|
||||
|
||||
#ifdef WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
hostname_string = hostname;
|
||||
}
|
||||
|
||||
return hostname_string;
|
||||
}
|
||||
|
||||
|
||||
std::string net_get_dns()
|
||||
{
|
||||
std::string dns_suffix;
|
||||
|
||||
std::vector<unsigned char> address;
|
||||
cmd_get_wired_mac_address(address);
|
||||
|
||||
if (address.size() == 6)
|
||||
{
|
||||
char macAddress[6];
|
||||
macAddress[0] = address[0];
|
||||
macAddress[1] = address[1];
|
||||
macAddress[2] = address[2];
|
||||
macAddress[3] = address[3];
|
||||
macAddress[4] = address[4];
|
||||
macAddress[5] = address[5];
|
||||
|
||||
// get DNS from OS
|
||||
dns_suffix = net_get_dns(macAddress);
|
||||
}
|
||||
|
||||
return dns_suffix;
|
||||
}
|
||||
|
@@ -9,5 +9,7 @@
|
||||
#include <string>
|
||||
|
||||
std::string net_get_dns(char* macAddress);
|
||||
std::string net_get_hostname();
|
||||
std::string net_get_dns();
|
||||
|
||||
#endif
|
@@ -40,6 +40,7 @@ void usage_show_help()
|
||||
std::cout << " uuid unique identifier" << std::endl;
|
||||
std::cout << " mode current control mode" << std::endl;
|
||||
std::cout << " dns domain name suffix" << std::endl;
|
||||
std::cout << " fqdn fully qualified domain name" << std::endl;
|
||||
std::cout << " cert certificate hashes" << std::endl;
|
||||
std::cout << " ras remote access status" << std::endl;
|
||||
std::cout << " lan LAN settings" << std::endl;
|
||||
|
Reference in New Issue
Block a user