Remote: paste the phone clipboard, including images, on the desktop
CI / test (push) Failing after 1m2s

- Web UI: Ctrl+V, Ctrl+Shift+V, Shift+Insert (Cmd+V on Mac) and a Paste button send the phone clipboard (text or PNG, up to 16 MB) to the desktop over POST /api/clipboard
- chandra-remote passes clipboard data to the compositor in a sealed memfd (clipboard-set-fd), replacing the 4 KB hex clipboard-set line
- Compositor: new clipboard-status and input-paste commands; text is typed into the launcher, password dialog and shell popups, otherwise the paste chord is sent (Ctrl+Shift+V in terminals)
- Paste data is captured when a paste starts, so a clipboard change mid-transfer can't corrupt it
- VNC clipboard text limit raised from 4 KB to 1 MB
- Upload endpoints are authorized with the same token check as /ws; the no-header cross-site case is refused with 403
This commit is contained in:
nandi committed 2026-11-29 15:42:46 -08:00
1 parent 8a6d19d16f
commit d2e00b4658
11 files changed
+853 -68

No files matched your search

+66 -5
View File
@@ -1,3 +1,4 @@
#define _GNU_SOURCE /* memfd_create, file seals */
#include "remote_internal.h"
#include <arpa/inet.h>
@@ -121,7 +122,8 @@ void ctl_close(CtlConn *c) {
pthread_mutex_unlock(&c->mu);
}
static int ctl_once_locked(CtlConn *c, const char *line, char *reply, size_t reply_cap) {
/* `send_fd` (-1 for none) goes along with the first bytes of the line as SCM_RIGHTS. */
static int ctl_once_locked(CtlConn *c, const char *line, int send_fd, char *reply, size_t reply_cap) {
if (c->fd < 0) {
uint64_t now = remote_now_ms();
if (now - c->last_try_ms < 250) return -1;
@@ -136,7 +138,26 @@ static int ctl_once_locked(CtlConn *c, const char *line, char *reply, size_t rep
msg[l] = '\n';
size_t sent = 0;
while (sent < l + 1) {
ssize_t w = send(c->fd, msg + sent, l + 1 - sent, MSG_NOSIGNAL);
struct iovec iov = { .iov_base = msg + sent, .iov_len = l + 1 - sent };
struct msghdr mh;
memset(&mh, 0, sizeof mh);
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
union {
struct cmsghdr align;
char buf[CMSG_SPACE(sizeof(int))];
} cm;
if (send_fd >= 0 && sent == 0) {
memset(&cm, 0, sizeof cm);
mh.msg_control = cm.buf;
mh.msg_controllen = sizeof cm.buf;
struct cmsghdr *ch = CMSG_FIRSTHDR(&mh);
ch->cmsg_level = SOL_SOCKET;
ch->cmsg_type = SCM_RIGHTS;
ch->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(ch), &send_fd, sizeof(int));
}
ssize_t w = sendmsg(c->fd, &mh, MSG_NOSIGNAL);
if (w <= 0) {
free(msg);
close(c->fd);
@@ -188,21 +209,61 @@ static int ctl_once_locked(CtlConn *c, const char *line, char *reply, size_t rep
return ok;
}
int ctl_cmd(CtlConn *c, const char *line, char *reply, size_t reply_cap) {
static int ctl_cmd_fd(CtlConn *c, const char *line, int send_fd, char *reply, size_t reply_cap) {
pthread_mutex_lock(&c->mu);
int r = ctl_once_locked(c, line, reply, reply_cap);
int r = ctl_once_locked(c, line, send_fd, reply, reply_cap);
if (r < 0) {
c->last_try_ms = 0;
r = ctl_once_locked(c, line, reply, reply_cap);
r = ctl_once_locked(c, line, send_fd, reply, reply_cap);
}
pthread_mutex_unlock(&c->mu);
return r;
}
int ctl_cmd(CtlConn *c, const char *line, char *reply, size_t reply_cap) {
return ctl_cmd_fd(c, line, -1, reply, reply_cap);
}
int ctl_fire(CtlConn *c, const char *line) {
return ctl_cmd(c, line, NULL, 0);
}
static int parse_serial(const char *reply, unsigned long *serial) {
unsigned long s = 0;
if (sscanf(reply, "ok serial=%lu", &s) != 1) return -1;
if (serial) *serial = s;
return 0;
}
int remote_clipboard_serial(CtlConn *c, unsigned long *serial) {
char reply[64] = {0};
if (ctl_cmd(c, "clipboard-status", reply, sizeof reply) != 0) return -1;
return parse_serial(reply, serial);
}
/* A control line holds at most 4 KB, so the data goes in a sealed memfd passed along with it. */
int remote_clipboard_set(CtlConn *c, const char *mime, const void *data, size_t len,
unsigned long *serial) {
if (len == 0 || len > REMOTE_CLIPBOARD_MAX) return -1;
int fd = memfd_create("chandra-remote-clipboard", MFD_CLOEXEC | MFD_ALLOW_SEALING);
if (fd < 0) return -1;
const uint8_t *p = data;
size_t done = 0;
while (done < len) {
ssize_t w = write(fd, p + done, len - done);
if (w < 0 && errno == EINTR) continue;
if (w <= 0) { close(fd); return -1; }
done += (size_t)w;
}
fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE | F_SEAL_SEAL);
char cmd[96], reply[128] = {0};
snprintf(cmd, sizeof cmd, "clipboard-set-fd %s %zu", mime, len);
int r = ctl_cmd_fd(c, cmd, fd, reply, sizeof reply);
close(fd);
if (r != 0) return -1;
return parse_serial(reply, serial);
}
void remote_osk_suppress_acquire(RemoteApp *app, int *client_flag) {
if (*client_flag) return;
pthread_mutex_lock(&app->osk_mu);