Skip to content

Commit

Permalink
Strip "QUBESRPC " prefix from service call commands
Browse files Browse the repository at this point in the history
It carries no information, and various parts of the code must strip it.
Just omit it from the command entirely.  Whether a command is an RPC
command should be determined by the service descriptor being non-NULL.

Review with "git diff --ignore-space-change".
  • Loading branch information
DemiMarie committed Jan 31, 2025
1 parent c6b3619 commit f4dfe46
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 190 deletions.
24 changes: 14 additions & 10 deletions agent/qrexec-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
exit(1);
}
/* call QUBESRPC if requested */
/* no point in creating a login shell for test environments */
exec_qubes_rpc_if_requested2(prog, cmd, environ, false);
if (prog) {
/* no point in creating a login shell for test environments */
exec_qubes_rpc2(prog, cmd, environ, false);
}

/* otherwise exec shell */
execl("/bin/sh", "sh", "-c", cmd, NULL);
Expand Down Expand Up @@ -279,10 +281,11 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
if (retval == -1)
warn("chdir(%s)", pw->pw_dir);

/* Call QUBESRPC if requested, using a login shell to set up
* environment variables. */
exec_qubes_rpc_if_requested2(prog, cmd, env, true);

/* call QUBESRPC if requested */
if (prog) {
/* Set up environment variables for a login shell. */
exec_qubes_rpc2(prog, cmd, env, true);
}
/* otherwise exec shell */
execle(pw->pw_shell, arg0, "-c", cmd, (char*)NULL, env);
_exit(QREXEC_EXIT_PROBLEM);
Expand Down Expand Up @@ -318,10 +321,11 @@ _Noreturn void do_exec(const char *prog, const char *cmd, const char *user)
pam_end(pamh, PAM_ABORT);
exit(1);
#else
/* Call QUBESRPC if requested, using a login shell to set up
* environment variables. */
exec_qubes_rpc_if_requested2(prog, cmd, environ, true);

/* call QUBESRPC if requested */
if (prog) {
/* Set up environment variables for a login session. */
exec_qubes_rpc2(prog, cmd, environ, true);
}
/* otherwise exec shell */
execl("/bin/su", "su", "-", user, "-c", cmd, NULL);
PERROR("execl");
Expand Down
7 changes: 5 additions & 2 deletions agent/qrexec-fork-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ void do_exec(const char *prog, const char *cmd, const char *user __attribute__((
signal(SIGCHLD, SIG_DFL);
signal(SIGPIPE, SIG_DFL);

/* Call QUBESRPC if requested. This code already runs in a login session. */
exec_qubes_rpc_if_requested2(prog, cmd, environ, false);
/* call QUBESRPC if requested */
if (prog != NULL) {
/* Already in login session. */
exec_qubes_rpc2(prog, cmd, environ, false);
}

/* otherwise, pass it to shell */
shell = getenv("SHELL");
Expand Down
17 changes: 8 additions & 9 deletions daemon/qrexec-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ static _Noreturn void do_exec(const char *prog,
const char *cmdline,
const char *username __attribute__((unused)))
{
/* Avoid calling RPC command through shell.
* Qrexec-client is always in a login session. */
exec_qubes_rpc_if_requested2(prog, cmdline, environ, false);
/* avoid calling RPC service through shell */
if (prog) {
/* qrexec-client is always in a login session. */
exec_qubes_rpc2(prog, cmdline, environ, false);
}

/* if above haven't executed RPC command, pass it to shell */
/* if above haven't executed RPC service, pass it to shell */
execl("/bin/bash", "bash", "-c", cmdline, NULL);
PERROR("exec bash");
exit(1);
Expand Down Expand Up @@ -326,11 +328,8 @@ int main(int argc, char **argv)
assert(command->username == NULL);
assert(command->command);
/* qrexec-client is always in a login session. */
exec_qubes_rpc_if_requested2(buf.data, command->command, environ, false);
/* not reached, so fall through to crash */
assert(false);
rc = QREXEC_EXIT_PROBLEM;
break;
exec_qubes_rpc2(buf.data, command->command, environ, false);
/* not reached */
default:
assert(false);
rc = QREXEC_EXIT_PROBLEM;
Expand Down
8 changes: 5 additions & 3 deletions daemon/qrexec-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,9 +1133,11 @@ static enum policy_response connect_daemon_socket(
/* called from do_fork_exec */
static _Noreturn void do_exec(const char *prog, const char *cmd, const char *username __attribute__((unused)))
{
/* Avoid calling RPC command through shell.
* Qrexec-daemon is always in a login session already. */
exec_qubes_rpc_if_requested2(prog, cmd, environ, true);
/* avoid calling RPC command through shell */
if (prog) {
/* qrexec-daemon is always in a login session already */
exec_qubes_rpc2(prog, cmd, environ, false);
}

/* if above haven't executed RPC command, pass it to shell */
execl("/bin/bash", "bash", "-c", cmd, NULL);
Expand Down
Loading

0 comments on commit f4dfe46

Please sign in to comment.