harden ipc and frontend recovery

This commit is contained in:
2026-08-11 19:34:47 +09:00
parent 4bfb659b6d
commit 9dc116a035
14 changed files with 495 additions and 245 deletions

View File

@@ -1,3 +1,4 @@
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -5,13 +6,7 @@
#include <time.h>
#include <sys/socket.h>
#include <sys/un.h>
enum {
Kback = 0xf008,
Kret = 0xf00d,
Kesc = 0xf01b,
Mctrl = 1<<2,
};
#include "../ipc.h"
typedef struct Key Key;
struct Key {
@@ -93,8 +88,7 @@ dial(void)
die("socket");
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
snprintf(addr.sun_path, sizeof(addr.sun_path),
"/tmp/strans.%d", getuid());
snprintf(addr.sun_path, sizeof(addr.sun_path), IPCPATH, getuid());
if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0)
die("connect");
}
@@ -102,28 +96,20 @@ dial(void)
static void
sendkey(int key, int mod)
{
unsigned char req[4];
unsigned char req[Ipcreqsz];
req[0] = 0;
req[1] = mod;
req[2] = key & 0xff;
req[3] = (key >> 8) & 0xff;
if(write(fd, req, 4) != 4)
ipcpackreq(req, 0, mod, key);
if(ipcsend(fd, req, sizeof req) < 0)
die("write");
}
static int
readresp(void)
{
unsigned char buf[256];
int n;
char buf[Ipcfieldmax+1];
Ipcresp resp;
if(read(fd, buf, 2) != 2)
return -1;
n = buf[1];
if(n > 0 && read(fd, buf + 2, n) != n)
return -1;
return 0;
return ipcreadresp(fd, 0, buf, sizeof buf, NULL, 0, &resp);
}
static double