osc: add option to disable OSC-52, partially or fully

Closes #1867
This commit is contained in:
Daniel Eklöf 2024-12-21 06:52:00 +01:00
parent 67bd5dd460
commit e38ec79be1
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
7 changed files with 99 additions and 1 deletions

17
osc.c
View file

@ -8,7 +8,7 @@
#include <sys/epoll.h>
#define LOG_MODULE "osc"
#define LOG_ENABLE_DBG 0
#define LOG_ENABLE_DBG 1
#include "log.h"
#include "base64.h"
#include "config.h"
@ -64,6 +64,14 @@ osc_to_clipboard(struct terminal *term, const char *target,
return;
}
const bool copy_allowed = term->conf->security.osc52 == OSC52_ENABLED
|| term->conf->security.osc52 == OSC52_COPY_ENABLED;
if (!copy_allowed) {
LOG_DBG("ignoring copy request: disabled in configuration");
return;
}
char *decoded = base64_decode(base64_data, NULL);
if (decoded == NULL) {
if (errno == EINVAL)
@ -190,6 +198,13 @@ osc_from_clipboard(struct terminal *term, const char *source)
return;
}
const bool paste_allowed = term->conf->security.osc52 == OSC52_ENABLED
|| term->conf->security.osc52 == OSC52_PASTE_ENABLED;
if (!paste_allowed) {
LOG_DBG("ignoring paste request: disabled in configuration");
return;
}
/* Use clipboard if no source has been specified */
char src = source[0] == '\0' ? 'c' : 0;
bool from_clipboard = src == 'c';