608 lines
18 KiB
C#
608 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Runtime.InteropServices;
|
|
using System.Management.Automation.Provider;
|
|
using Intel.Management.Wsman;
|
|
|
|
|
|
namespace Intel.Management.PSModule.Amt
|
|
{
|
|
class EventLogService : DriveContainer
|
|
{
|
|
|
|
public EventLogService(DriveItem parent)
|
|
: base("Logs", parent)
|
|
{
|
|
}
|
|
|
|
public override void GetChildItems(ChildWriter writer)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
|
|
IManagedReference eventLogRef = conn.NewReference("AMT_MessageLog");
|
|
eventLogRef.AddSelector("Name", "Intel(r) AMT:MessageLog 1");
|
|
|
|
IManagedReference auditLogRef = conn.NewReference("AMT_AuditLog");
|
|
auditLogRef.AddSelector("Name", "Intel(r) AMT:Audit Log");
|
|
|
|
writer.Add(new Log(eventLogRef, "EventLog", this));
|
|
writer.Add(new AuditLogService(auditLogRef, this));
|
|
|
|
|
|
writer.Add(new IDERLog(this));
|
|
writer.Add(new SetupLog( this));
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
|
|
class IDERLog : DriveItem
|
|
{
|
|
public IDERLog(DriveItem parent)
|
|
: base("Redirection",new Content(), parent)
|
|
{
|
|
}
|
|
|
|
public override IContentReader GetContentReader( DriveProvider provider)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
IManagedReference refToLog = conn.NewReference("AMT_RedirectionService");
|
|
|
|
return new IDERLogReader(refToLog);
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
|
|
class IDERLogReader : IContentReader
|
|
{
|
|
IManagedReference _refToLog;
|
|
int _count;
|
|
|
|
|
|
public IDERLogReader(IManagedReference refToLog)
|
|
{
|
|
_refToLog = refToLog;
|
|
_count = -1;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
_count = -1;
|
|
}
|
|
|
|
public void Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
}
|
|
|
|
public System.Collections.IList Read(long size)
|
|
{
|
|
|
|
System.Collections.IList list = new System.Collections.ArrayList();
|
|
|
|
if (_count < 0)
|
|
{
|
|
_count = 0;
|
|
IManagedInstance service = _refToLog.Get();
|
|
|
|
foreach (IWsmanItem item in service.GetProperty("AccessLog"))
|
|
{
|
|
|
|
list.Add(item.ToString());
|
|
_count++;
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
class SetupLog : DriveItem
|
|
{
|
|
public SetupLog(DriveItem parent)
|
|
: base("Setup", new Content(), parent)
|
|
{
|
|
}
|
|
|
|
public override IContentReader GetContentReader(DriveProvider provider)
|
|
{
|
|
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
|
|
IManagedReference refToLog = conn.NewReference("AMT_SetupAndConfigurationService");
|
|
|
|
return new SetupLogReader(refToLog);
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
}
|
|
|
|
|
|
class SetupLogReader : IContentReader
|
|
{
|
|
IManagedReference _refToLog;
|
|
int _count;
|
|
|
|
|
|
public SetupLogReader(IManagedReference refToLog)
|
|
{
|
|
_refToLog = refToLog;
|
|
_count = -1;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
_count = -1;
|
|
}
|
|
|
|
public void Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
}
|
|
|
|
public System.Collections.IList Read(long size)
|
|
{
|
|
|
|
System.Collections.IList list = new System.Collections.ArrayList();
|
|
|
|
if (_count < 0)
|
|
{
|
|
_count = 0;
|
|
IManagedInstance service = _refToLog.Get();
|
|
|
|
|
|
IManagedInstance inputObj = _refToLog.CreateMethodInput("GetProvisioningAuditRecord");
|
|
IManagedInstance outObj = _refToLog.InvokeMethod(inputObj);
|
|
|
|
if (outObj.GetProperty("ReturnValue").ToString().Equals("0"))
|
|
{
|
|
|
|
string suffix = outObj.GetProperty("ProvServerFQDN").ToString();
|
|
long sec = long.Parse(outObj.GetProperty("TlsStartTime").ToString());
|
|
|
|
DateTime timestamp = new DateTime(1970, 1, 1);
|
|
timestamp = timestamp.AddSeconds(sec);
|
|
|
|
uint isDefault = 0;
|
|
if (outObj.GetProperty("IsOemDefault").ToString().Equals("true"))
|
|
isDefault = 1;
|
|
|
|
uint isTimeValid = 0;
|
|
if (outObj.GetProperty("IsTimeValid").ToString().Equals("true"))
|
|
isTimeValid = 1;
|
|
|
|
uint additionalSerials = 0;
|
|
if (outObj.GetProperty("AdditionalCaSerialNums").ToString().Equals("true"))
|
|
additionalSerials = 1;
|
|
|
|
byte[] serials = new byte[0];
|
|
if (additionalSerials != 0)
|
|
serials = Convert.FromBase64String(outObj.GetProperty("CaCertificateSerials").ToString());
|
|
|
|
Intel.Management.Mei.HECIClass.HashAlgorithm hashAlg =
|
|
(Intel.Management.Mei.HECIClass.HashAlgorithm)
|
|
int.Parse(outObj.GetProperty("SelectedHashType").ToString());
|
|
|
|
|
|
Intel.Management.Mei.HECIClass.AuditRecord record =
|
|
new Intel.Management.Mei.HECIClass.AuditRecord(timestamp,
|
|
suffix,
|
|
uint.Parse(outObj.GetProperty("ProvServerIP").ToString()),
|
|
isDefault,
|
|
Convert.FromBase64String(outObj.GetProperty("SelectedHashData").ToString()),
|
|
hashAlg,
|
|
isTimeValid,
|
|
additionalSerials,
|
|
serials);
|
|
|
|
list.Add(record);
|
|
_count = 1;
|
|
}
|
|
}
|
|
|
|
|
|
return list;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
enum CharacterSetType
|
|
{
|
|
Unknown=0,
|
|
Other=1,
|
|
ASCII=2,
|
|
Unicode=3,
|
|
ISO2022=4,
|
|
ISO8859=5,
|
|
ExtendedUNIXCode=6,
|
|
UTF8=7,
|
|
UCS2=8,
|
|
BitmappedData=9,
|
|
OctetString=10,
|
|
DefinedByIndividualRecords=11
|
|
}
|
|
|
|
enum LastChangeType
|
|
{
|
|
Unknown=0,
|
|
Add=1,
|
|
Delete=2,
|
|
Modify=3,
|
|
Cleared=4
|
|
}
|
|
|
|
enum OverwritePolicyType
|
|
{
|
|
Unknown=0,
|
|
Other=1,
|
|
WrapsWhenFull=2,
|
|
ClearWhenNearFull=3,
|
|
OverwriteOutdatedWhenNeeded=4,
|
|
RemoveOutdatedRecords=5,
|
|
OverwriteSpecificRecords=6,
|
|
NeverOverwrite=7,
|
|
}
|
|
|
|
enum CapabilitiesType
|
|
{
|
|
Unknown=0,
|
|
Other=1,
|
|
WriteRecordSupported=2,
|
|
DeleteRecordSupported=3,
|
|
CanMoveBackward=4,
|
|
FreezeSupported=5,
|
|
ClearLogSupported=6,
|
|
SupportsAddressingByOrdinalRecordNumber=7,
|
|
VariableLengthRecordsSupported=8,
|
|
VariableFormatsForRecords=9,
|
|
CanFlagRecordsForOverwrite=10
|
|
}
|
|
|
|
enum LogStateType
|
|
{
|
|
Unknown=0,
|
|
Normal=2,
|
|
Erasing=3,
|
|
NotApplicable=4,
|
|
}
|
|
|
|
|
|
class AmtLogReader : IContentReader
|
|
{
|
|
IManagedReference _refToLog;
|
|
string _iterator;
|
|
bool _reading;
|
|
List<byte[]> _records;
|
|
IFormatProvider _formatProvider;
|
|
|
|
public AmtLogReader(IManagedReference refToLog)
|
|
{
|
|
_refToLog = refToLog;
|
|
_records = new List<byte[]>();
|
|
_reading=true;
|
|
_formatProvider = new MessageFormat();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public void Close()
|
|
{
|
|
_iterator = null;
|
|
}
|
|
|
|
public void Seek(long offset, System.IO.SeekOrigin origin)
|
|
{
|
|
}
|
|
|
|
public System.Collections.IList Read(long size)
|
|
{
|
|
|
|
System.Collections.IList list = new System.Collections.ArrayList();
|
|
|
|
if (_iterator == null)
|
|
PositionToFirstRecord();
|
|
|
|
if (_iterator != null)
|
|
{
|
|
if (_records.Count < size && _reading)
|
|
GetRecords();
|
|
|
|
for (int i=0; i<size && _records.Count>0; i++)
|
|
{
|
|
byte[] data = _records[0];
|
|
_records.RemoveAt(0);
|
|
|
|
IntPtr recPtr = Marshal.AllocCoTaskMem(data.Length);
|
|
try
|
|
{
|
|
Marshal.Copy(data, 0, recPtr, data.Length);
|
|
|
|
list.Add(AmtMessageLogEntry.CreateFromPtr(recPtr,_formatProvider));
|
|
}
|
|
finally
|
|
{
|
|
Marshal.FreeCoTaskMem(recPtr);
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
|
|
void PositionToFirstRecord()
|
|
{
|
|
IManagedInstance inputObj = _refToLog.CreateMethodInput("PositionToFirstRecord");
|
|
IManagedInstance outObj = _refToLog.InvokeMethod(inputObj);
|
|
|
|
string returnValue = outObj.GetProperty("ReturnValue").ToString();
|
|
|
|
if (returnValue.Equals("0"))
|
|
{
|
|
_iterator= outObj.GetProperty("IterationIdentifier").ToString();
|
|
}
|
|
else if (returnValue.Equals("1"))
|
|
{
|
|
ThrowReadError(outObj, returnValue, "Not Supported");
|
|
}
|
|
}
|
|
|
|
void GetRecords()
|
|
{
|
|
IManagedInstance inputObj = _refToLog.CreateMethodInput("GetRecords");
|
|
inputObj.SetProperty("IterationIdentifier", _iterator);
|
|
inputObj.SetProperty("MaxReadRecords","195");
|
|
|
|
|
|
IManagedInstance outObj = _refToLog.InvokeMethod(inputObj);
|
|
string returnValue = outObj.GetProperty("ReturnValue").ToString();
|
|
|
|
|
|
if (returnValue.Equals("0"))
|
|
{
|
|
foreach (IWsmanItem item in outObj.GetProperty("RecordArray"))
|
|
{
|
|
_records.Add(Convert.FromBase64String(item.ToString()));
|
|
}
|
|
_iterator = outObj.GetProperty("IterationIdentifier").ToString();
|
|
_reading = outObj.GetProperty("NoMoreRecords").ToString().Equals("false");
|
|
}
|
|
else if (returnValue.Equals("1"))
|
|
{
|
|
ThrowReadError(outObj, returnValue, "Not Supported");
|
|
}
|
|
else if (returnValue.Equals("2"))
|
|
{
|
|
ThrowReadError(outObj, returnValue, "Invalid record pointed");
|
|
}
|
|
else if (returnValue.Equals("3"))
|
|
{
|
|
ThrowReadError(outObj, returnValue, "No record exists in log");
|
|
}
|
|
}
|
|
|
|
void ThrowReadError(IManagedInstance resultObj,string value,string message)
|
|
{
|
|
StringBuilder builder = new StringBuilder();
|
|
builder.Append(resultObj.SimpleName);
|
|
builder.Append(".ReturnValue=");
|
|
builder.Append(value);
|
|
builder.Append(" ");
|
|
builder.Append(message);
|
|
throw new AmtException(builder.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
|
|
class Log : DriveItem
|
|
{
|
|
IManagedReference _refToLog;
|
|
|
|
static string[] _properties = {"CharacterSet",
|
|
"IsFrozen",
|
|
"LastChange",
|
|
"PercentageNearFull",
|
|
"OverwritePolicy",
|
|
"SizeOfRecordHeader",
|
|
"MaxRecordSize",
|
|
"SizeOfHeader",
|
|
"MaxLogSize",
|
|
"Capabilities",
|
|
"MaxNumberOfRecords",
|
|
"CurrentNumberOfRecords",
|
|
"LogState",};
|
|
|
|
CharacterSetType _characterSet;
|
|
bool _isFrozen;
|
|
LastChangeType _lastChange;
|
|
int _percentageNearFull;
|
|
OverwritePolicyType _overwritePolicy;
|
|
ulong _sizeOfRecordHeader;
|
|
ulong _maxRecordSize;
|
|
ulong _sizeOfHeader;
|
|
ulong _maxLogSize;
|
|
CapabilitiesType[] _capabilities;
|
|
ulong _maxNumberOfRecords;
|
|
ulong _currentNumberOfRecords;
|
|
LogStateType _logState;
|
|
|
|
|
|
|
|
public Log(IManagedReference refToLog,string logName,DriveItem parent)
|
|
: base(logName,new Content(), parent)
|
|
{
|
|
IManagedInstance logObj = refToLog.Get();
|
|
|
|
_characterSet= (CharacterSetType)int.Parse(logObj.GetProperty("CharacterSet").ToString());
|
|
_isFrozen=bool.Parse(logObj.GetProperty("IsFrozen").ToString());
|
|
_lastChange=(LastChangeType)int.Parse(logObj.GetProperty("LastChange").ToString());
|
|
_percentageNearFull=int.Parse(logObj.GetProperty("PercentageNearFull").ToString());
|
|
_overwritePolicy=(OverwritePolicyType)int.Parse(logObj.GetProperty("OverwritePolicy").ToString());
|
|
_sizeOfRecordHeader=ulong.Parse(logObj.GetProperty("SizeOfRecordHeader").ToString());
|
|
_maxRecordSize=ulong.Parse(logObj.GetProperty("MaxRecordSize").ToString());
|
|
_sizeOfHeader=ulong.Parse(logObj.GetProperty("SizeOfHeader").ToString());
|
|
_maxLogSize=ulong.Parse(logObj.GetProperty("MaxLogSize").ToString());
|
|
|
|
List<CapabilitiesType> caps = new List<CapabilitiesType>();
|
|
foreach (IWsmanItem item in logObj.GetProperty("Capabilities"))
|
|
{
|
|
caps.Add((CapabilitiesType)int.Parse(item.ToString()));
|
|
}
|
|
_capabilities=caps.ToArray();
|
|
_maxNumberOfRecords=ulong.Parse(logObj.GetProperty("MaxNumberOfRecords").ToString());
|
|
_currentNumberOfRecords=ulong.Parse(logObj.GetProperty("CurrentNumberOfRecords").ToString());
|
|
|
|
|
|
if (!logObj.GetProperty("LogState").IsNull)
|
|
_logState = (LogStateType)int.Parse(logObj.GetProperty("LogState").ToString());
|
|
|
|
_refToLog = refToLog;
|
|
|
|
}
|
|
|
|
public override IContentReader GetContentReader( DriveProvider provider)
|
|
{
|
|
return new AmtLogReader(_refToLog);
|
|
}
|
|
|
|
public override object GetReturnObject()
|
|
{
|
|
return new NameValuePairItem(Name, Value);
|
|
}
|
|
|
|
|
|
|
|
public override string[] Properties
|
|
{
|
|
get { return _properties; }
|
|
}
|
|
|
|
public CharacterSetType CharacterSet
|
|
{
|
|
get
|
|
{
|
|
return _characterSet;
|
|
}
|
|
}
|
|
|
|
public bool IsFrozen
|
|
{
|
|
get
|
|
{
|
|
return _isFrozen;
|
|
}
|
|
}
|
|
|
|
public LastChangeType LastChange
|
|
{
|
|
get
|
|
{
|
|
return _lastChange;
|
|
}
|
|
}
|
|
|
|
public int PercentageNearFull
|
|
{
|
|
get
|
|
{
|
|
return _percentageNearFull;
|
|
}
|
|
}
|
|
|
|
public OverwritePolicyType OverwritePolicy
|
|
{
|
|
get
|
|
{
|
|
return _overwritePolicy;
|
|
}
|
|
}
|
|
|
|
public ulong SizeOfRecordHeader
|
|
{
|
|
get
|
|
{
|
|
return _sizeOfRecordHeader;
|
|
}
|
|
}
|
|
|
|
public ulong MaxRecordSize
|
|
{
|
|
get
|
|
{
|
|
return _maxRecordSize;
|
|
}
|
|
}
|
|
|
|
public ulong SizeOfHeader
|
|
{
|
|
get
|
|
{
|
|
return _sizeOfHeader;
|
|
}
|
|
}
|
|
|
|
public ulong MaxLogSize
|
|
{
|
|
get
|
|
{
|
|
return _maxLogSize;
|
|
}
|
|
}
|
|
|
|
public CapabilitiesType[] Capabilities
|
|
{
|
|
get
|
|
{
|
|
return _capabilities;
|
|
}
|
|
}
|
|
|
|
public ulong MaxNumberOfRecords
|
|
{
|
|
get
|
|
{
|
|
return _maxNumberOfRecords;
|
|
}
|
|
}
|
|
|
|
public ulong CurrentNumberOfRecords
|
|
{
|
|
get
|
|
{
|
|
return _currentNumberOfRecords;
|
|
}
|
|
}
|
|
|
|
public LogStateType LogState
|
|
{
|
|
get
|
|
{
|
|
return _logState;
|
|
}
|
|
}
|
|
}
|
|
|
|
} //end eventlog service
|
|
}// end namespace
|