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:
@@ -219,6 +219,17 @@ namespace DiscImageChef.Devices
|
||||
public byte[] Cis { get; }
|
||||
|
||||
private readonly Remote.Remote _remote;
|
||||
private bool? _isRemoteAdmin;
|
||||
|
||||
public bool IsRemoteAdmin
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_isRemoteAdmin is null) _isRemoteAdmin = _remote.IsRoot;
|
||||
|
||||
return _isRemoteAdmin == true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsRemote => _remote != null;
|
||||
public string RemoteApplication => _remote?.ServerApplication;
|
||||
|
||||
@@ -27,7 +27,9 @@ namespace DiscImageChef.Devices.Remote
|
||||
ResponseGetFireWireData = 22,
|
||||
CommandGetPcmciaData = 23,
|
||||
ResponseGetPcmciaData = 24,
|
||||
CommandCloseDevice = 25
|
||||
CommandCloseDevice = 25,
|
||||
CommandAmIRoot = 26,
|
||||
ResponseAmIRoot = 27
|
||||
}
|
||||
|
||||
public enum DicNopReason : byte
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -320,4 +320,17 @@ namespace DiscImageChef.Devices.Remote
|
||||
{
|
||||
public DicPacketHeader hdr;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
||||
public struct DicPacketCmdAmIRoot
|
||||
{
|
||||
public DicPacketHeader hdr;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
|
||||
public struct DicPacketResAmIRoot
|
||||
{
|
||||
public DicPacketHeader hdr;
|
||||
[MarshalAs(UnmanagedType.U4)] public bool am_i_root;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user