mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add packet to check if remote is running as root.
This commit is contained in:
@@ -140,6 +140,71 @@ namespace DiscImageChef.Devices.Remote
|
||||
public string ServerArchitecture { get; }
|
||||
public int ServerProtocolVersion { get; }
|
||||
|
||||
public bool IsRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
var cmdPkt = new DicPacketCmdAmIRoot
|
||||
{
|
||||
hdr = new DicPacketHeader
|
||||
{
|
||||
remote_id = Consts.RemoteId, packet_id = Consts.PacketId,
|
||||
len = (uint) Marshal.SizeOf<DicPacketCmdAmIRoot>(),
|
||||
version = Consts.PacketVersion,
|
||||
packetType = DicPacketType.CommandAmIRoot
|
||||
}
|
||||
};
|
||||
|
||||
var buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt);
|
||||
|
||||
var len = _socket.Send(buf, SocketFlags.None);
|
||||
|
||||
if (len != buf.Length)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Could not write to the network...");
|
||||
return false;
|
||||
}
|
||||
|
||||
var hdrBuf = new byte[Marshal.SizeOf<DicPacketHeader>()];
|
||||
|
||||
len = Receive(_socket, hdrBuf, hdrBuf.Length, SocketFlags.Peek);
|
||||
|
||||
if (len < hdrBuf.Length)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Could not read from the network...");
|
||||
return false;
|
||||
}
|
||||
|
||||
var hdr = Marshal.ByteArrayToStructureLittleEndian<DicPacketHeader>(hdrBuf);
|
||||
|
||||
if (hdr.remote_id != Consts.RemoteId || hdr.packet_id != Consts.PacketId)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Received data is not a DIC Remote Packet...");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hdr.packetType != DicPacketType.ResponseAmIRoot)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Expected Am I Root? Response Packet, got packet type {0}...",
|
||||
hdr.packetType);
|
||||
return false;
|
||||
}
|
||||
|
||||
buf = new byte[hdr.len];
|
||||
len = Receive(_socket, buf, buf.Length, SocketFlags.None);
|
||||
|
||||
if (len < buf.Length)
|
||||
{
|
||||
DicConsole.ErrorWriteLine("Could not read from the network...");
|
||||
return false;
|
||||
}
|
||||
|
||||
var res = Marshal.ByteArrayToStructureLittleEndian<DicPacketResAmIRoot>(buf);
|
||||
|
||||
return res.am_i_root;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Disconnect();
|
||||
|
||||
Reference in New Issue
Block a user