Skip to content

Commit

Permalink
WIP: Support for source domain in RPC service
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Jan 22, 2025
1 parent b40d3da commit 809e50a
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 71 deletions.
10 changes: 6 additions & 4 deletions agent/qrexec-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,17 +799,19 @@ static void reap_children(void)
static void handle_trigger_io(void)
{
struct msg_header hdr;
struct trigger_service_params3 *params = NULL;
struct trigger_service_params4 *params = NULL;
int client_fd;

client_fd = do_accept(trigger_fd);
if (client_fd < 0)
return;
if (!read_all(client_fd, &hdr, sizeof(hdr)))
goto error;
if (hdr.type != MSG_TRIGGER_SERVICE3 ||
hdr.len <= sizeof(*params) ||
hdr.len > sizeof(*params) + MAX_SERVICE_NAME_LEN) {
if (
hdr.type != MSG_TRIGGER_SERVICE4 ||
hdr.len <= sizeof(*params) ||
hdr.len > sizeof(*params) + MAX_SERVICE_NAME_LEN
) {
LOG(ERROR, "Invalid request received from qrexec-client-vm, is it outdated?");
goto error;
}
Expand Down
2 changes: 1 addition & 1 deletion agent/qrexec-agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ extern const bool qrexec_is_fork_server;
pid_t handle_new_process(int type,
int connect_domain, int connect_port,
struct qrexec_parsed_command *cmd);

int handle_data_client(int type,
int connect_domain, int connect_port,
int stdin_fd, int stdout_fd,
int buffer_size, pid_t pid, const char *extra_data);


struct qrexec_cmd_info {
int type;
int connect_domain;
Expand Down
20 changes: 15 additions & 5 deletions agent/qrexec-client-vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static struct option longopts[] = {
{ "agent-socket", required_argument, 0, 'a'},
{ "prefix-data", required_argument, 0, 'p' },
{ "use-stdin-socket", no_argument, 0, opt_use_stdin_socket },
{ "source-qube", required_argument, 0, 's' },
{ "help", no_argument, 0, 'h' },
{ NULL, 0, 0, 0},
};
Expand All @@ -127,14 +128,15 @@ _Noreturn static void usage(const char *argv0, int status) {
QREXEC_AGENT_TRIGGER_PATH);
fprintf(stream, " -p PREFIX-DATA, --prefix-data=PREFIX-DATA - send the given data before the provided stdin (can only be used once)\n");
fprintf(stream, " --use-stdin-socket - use fd 0 (which must be socket) for both stdin and stdout\n");
fprintf(stderr, " -s SOURCE-QUBE, --source-qubes=SOURCE-QUBE - Specify the source qube. This option provides extra information for relayed connection that may be used during policy evaluation.\n");
exit(status);
}

int main(int argc, char **argv)
{
int trigger_fd;
struct msg_header hdr;
struct trigger_service_params3 params;
struct trigger_service_params4 params;
struct exec_params exec_params;
size_t service_name_len;
char *service_name, *endptr;
Expand All @@ -148,14 +150,15 @@ int main(int argc, char **argv)
int opt;
int stdout_fd = 1;
const char *agent_trigger_path = QREXEC_AGENT_TRIGGER_PATH, *prefix_data = NULL;
const char *source_qube = NULL;

setup_logging("qrexec-client-vm");

// TODO: this should be in qrexec_process_io
signal(SIGPIPE, SIG_IGN);

while (1) {
opt = getopt_long(argc, argv, "+tTa:hp:", longopts, NULL);
opt = getopt_long(argc, argv, "+tTa:p:s:h", longopts, NULL);
if (opt == -1)
break;
switch (opt) {
Expand Down Expand Up @@ -192,6 +195,11 @@ int main(int argc, char **argv)
usage(argv[0], 2);
prefix_data = optarg;
break;
case 's':
if (source_qube)
usage(argv[0], 2);
source_qube = optarg;
break;
case opt_no_filter_stdout:
replace_chars_stdout = 0;
break;
Expand Down Expand Up @@ -250,14 +258,16 @@ int main(int argc, char **argv)

trigger_fd = connect_unix_socket(agent_trigger_path);

hdr.type = MSG_TRIGGER_SERVICE3;
hdr.type = MSG_TRIGGER_SERVICE4;
hdr.len = sizeof(params) + service_name_len;

memset(&params, 0, sizeof(params));

if (source_qube!=NULL)
strncpy(params.source_domain, source_qube, sizeof(source_qube) - 1);

convert_target_name_keyword(argv[optind]);
strncpy(params.target_domain, argv[optind],
sizeof(params.target_domain) - 1);
strncpy(params.target_domain, argv[optind], sizeof(params.target_domain) - 1);

memcpy(params.request_id.ident, "SOCKET", sizeof("SOCKET"));

Expand Down
2 changes: 1 addition & 1 deletion daemon/qrexec-daemon-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int handle_daemon_handshake(int fd)
return -1;
}

if (info.version != QREXEC_PROTOCOL_VERSION) {
if (info.version < QREXEC_PROTOCOL_V3) {
LOG(ERROR, "Incompatible daemon protocol version "
"(daemon %d, client %d)",
info.version, QREXEC_PROTOCOL_VERSION);
Expand Down
Loading

0 comments on commit 809e50a

Please sign in to comment.