mirror of
https://github.com/aaru-dps/aaruremote.git
synced 2025-12-16 19:24:37 +00:00
Add packet to check if running as root.
This commit is contained in:
14
dicmote.h
14
dicmote.h
@@ -63,6 +63,8 @@
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_GET_PCMCIA_DATA 23
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_GET_PCMCIA_DATA 24
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_CLOSE_DEVICE 25
|
||||
#define DICMOTE_PACKET_TYPE_COMMAND_AM_I_ROOT 26
|
||||
#define DICMOTE_PACKET_TYPE_RESPONSE_AM_I_ROOT 27
|
||||
#define DICMOTE_PROTOCOL_MAX 1
|
||||
#define DICMOTE_PACKET_NOP_REASON_OOO 0
|
||||
#define DICMOTE_PACKET_NOP_REASON_NOT_IMPLEMENTED 1
|
||||
@@ -424,6 +426,17 @@ typedef struct
|
||||
DicPacketHeader hdr;
|
||||
} DicPacketCmdClose;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
} DicPacketCmdAmIRoot;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DicPacketHeader hdr;
|
||||
uint32_t am_i_root;
|
||||
} DicPacketResAmIRoot;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
DeviceInfoList* ListDevices();
|
||||
@@ -529,4 +542,5 @@ int32_t NetClose(int32_t fd);
|
||||
void Initialize();
|
||||
void PlatformLoop(DicPacketHello* pkt_server_hello);
|
||||
void* WorkingLoop(void* arguments);
|
||||
uint8_t AmIRoot();
|
||||
#endif
|
||||
|
||||
@@ -17,9 +17,13 @@
|
||||
|
||||
#include "../dicmote.h"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void PlatformLoop(DicPacketHello* pkt_server_hello) { WorkingLoop(pkt_server_hello); }
|
||||
|
||||
uint8_t AmIRoot() { return geteuid() == 0; }
|
||||
@@ -63,3 +63,5 @@ void PlatformLoop(DicPacketHello* pkt_server_hello)
|
||||
if(buttonsDown & WPAD_BUTTON_HOME) { return; }
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t AmIRoot() { return 1; }
|
||||
36
worker.c
36
worker.c
@@ -47,6 +47,7 @@ void* WorkingLoop(void* arguments)
|
||||
DicPacketHello* pkt_server_hello;
|
||||
DicPacketHello* pkt_client_hello;
|
||||
DicPacketNop* pkt_nop;
|
||||
DicPacketResAmIRoot* pkt_res_am_i_root;
|
||||
DicPacketResAtaChs* pkt_res_ata_chs;
|
||||
DicPacketResAtaLba28* pkt_res_ata_lba28;
|
||||
DicPacketResAtaLba48* pkt_res_ata_lba48;
|
||||
@@ -1020,6 +1021,41 @@ void* WorkingLoop(void* arguments)
|
||||
device_ctx = NULL;
|
||||
skip_next_hdr = 1;
|
||||
continue;
|
||||
case DICMOTE_PACKET_TYPE_COMMAND_AM_I_ROOT:
|
||||
// Packet only contains header so, dummy
|
||||
in_buf = malloc(le32toh(pkt_hdr->len));
|
||||
|
||||
if(!in_buf)
|
||||
{
|
||||
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||
free(pkt_hdr);
|
||||
NetClose(cli_sock);
|
||||
continue;
|
||||
}
|
||||
|
||||
NetRecv(cli_sock, in_buf, le32toh(pkt_hdr->len), 0);
|
||||
free(in_buf);
|
||||
|
||||
pkt_res_am_i_root = malloc(sizeof(DicPacketResAmIRoot));
|
||||
if(!pkt_res_am_i_root)
|
||||
{
|
||||
printf("Fatal error %d allocating memory for packet, closing connection...\n", errno);
|
||||
free(pkt_hdr);
|
||||
NetClose(cli_sock);
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(pkt_res_am_i_root, 0, sizeof(DicPacketResAmIRoot));
|
||||
pkt_res_am_i_root->hdr.remote_id = htole32(DICMOTE_REMOTE_ID);
|
||||
pkt_res_am_i_root->hdr.packet_id = htole32(DICMOTE_PACKET_ID);
|
||||
pkt_res_am_i_root->hdr.version = DICMOTE_PACKET_VERSION;
|
||||
pkt_res_am_i_root->hdr.packet_type = DICMOTE_PACKET_TYPE_RESPONSE_AM_I_ROOT;
|
||||
pkt_res_am_i_root->hdr.len = htole32(sizeof(DicPacketResAmIRoot));
|
||||
pkt_res_am_i_root->am_i_root = AmIRoot();
|
||||
|
||||
NetWrite(cli_sock, pkt_res_am_i_root, le32toh(pkt_res_am_i_root->hdr.len));
|
||||
free(pkt_res_am_i_root);
|
||||
continue;
|
||||
default:
|
||||
pkt_nop->reason_code = DICMOTE_PACKET_NOP_REASON_NOT_RECOGNIZED;
|
||||
memset(&pkt_nop->reason, 0, 256);
|
||||
|
||||
Reference in New Issue
Block a user