qrexec: use exec_qubes_rpc_if_requested() from qubes-utils
This avoids duplicating service call parsing in multiple places. Further improvements to that code (like avoid using shell) can be implemented in one place.
This commit is contained in:
parent
68304ef9f5
commit
5512e4eada
@ -133,9 +133,8 @@ static struct pam_conv conv = {
|
|||||||
* If dom0 sends overly long cmd, it will probably crash qrexec-agent (unless
|
* If dom0 sends overly long cmd, it will probably crash qrexec-agent (unless
|
||||||
* process can allocate up to 4GB on both stack and heap), sorry.
|
* process can allocate up to 4GB on both stack and heap), sorry.
|
||||||
*/
|
*/
|
||||||
void do_exec(const char *cmd)
|
void do_exec(char *cmd)
|
||||||
{
|
{
|
||||||
char buf[strlen(QUBES_RPC_MULTIPLEXER_PATH) + strlen(cmd) - RPC_REQUEST_COMMAND_LEN + 1];
|
|
||||||
char *realcmd = index(cmd, ':'), *user;
|
char *realcmd = index(cmd, ':'), *user;
|
||||||
#ifdef HAVE_PAM
|
#ifdef HAVE_PAM
|
||||||
int retval, status;
|
int retval, status;
|
||||||
@ -157,12 +156,6 @@ void do_exec(const char *cmd)
|
|||||||
/* ignore "nogui:" prefix in linux agent */
|
/* ignore "nogui:" prefix in linux agent */
|
||||||
if (strncmp(realcmd, NOGUI_CMD_PREFIX, NOGUI_CMD_PREFIX_LEN) == 0)
|
if (strncmp(realcmd, NOGUI_CMD_PREFIX, NOGUI_CMD_PREFIX_LEN) == 0)
|
||||||
realcmd += NOGUI_CMD_PREFIX_LEN;
|
realcmd += NOGUI_CMD_PREFIX_LEN;
|
||||||
/* replace magic RPC cmd with RPC multiplexer path */
|
|
||||||
if (strncmp(realcmd, RPC_REQUEST_COMMAND " ", RPC_REQUEST_COMMAND_LEN+1)==0) {
|
|
||||||
strcpy(buf, QUBES_RPC_MULTIPLEXER_PATH);
|
|
||||||
strcpy(buf + strlen(QUBES_RPC_MULTIPLEXER_PATH), realcmd + RPC_REQUEST_COMMAND_LEN);
|
|
||||||
realcmd = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
signal(SIGPIPE, SIG_DFL);
|
signal(SIGPIPE, SIG_DFL);
|
||||||
@ -260,6 +253,11 @@ void do_exec(const char *cmd)
|
|||||||
retval = chdir(pw->pw_dir);
|
retval = chdir(pw->pw_dir);
|
||||||
if (retval == -1)
|
if (retval == -1)
|
||||||
warn("chdir(%s)", pw->pw_dir);
|
warn("chdir(%s)", pw->pw_dir);
|
||||||
|
|
||||||
|
/* call QUBESRPC if requested */
|
||||||
|
exec_qubes_rpc_if_requested(realcmd, env);
|
||||||
|
|
||||||
|
/* otherwise exec shell */
|
||||||
execle(pw->pw_shell, arg0, "-c", realcmd, (char*)NULL, env);
|
execle(pw->pw_shell, arg0, "-c", realcmd, (char*)NULL, env);
|
||||||
exit(127);
|
exit(127);
|
||||||
default:
|
default:
|
||||||
@ -294,6 +292,10 @@ error:
|
|||||||
pam_end(pamh, PAM_ABORT);
|
pam_end(pamh, PAM_ABORT);
|
||||||
exit(1);
|
exit(1);
|
||||||
#else
|
#else
|
||||||
|
/* call QUBESRPC if requested */
|
||||||
|
exec_qubes_rpc_if_requested(realcmd, environ);
|
||||||
|
|
||||||
|
/* otherwise exec shell */
|
||||||
execl("/bin/su", "su", "-", user, "-c", realcmd, NULL);
|
execl("/bin/su", "su", "-", user, "-c", realcmd, NULL);
|
||||||
perror("execl");
|
perror("execl");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
int handle_handshake(libvchan_t *ctrl);
|
int handle_handshake(libvchan_t *ctrl);
|
||||||
void handle_vchan_error(const char *op);
|
void handle_vchan_error(const char *op);
|
||||||
void do_exec(const char *cmd);
|
void do_exec(char *cmd);
|
||||||
/* call before fork() for service handling process (either end) */
|
/* call before fork() for service handling process (either end) */
|
||||||
void prepare_child_env();
|
void prepare_child_env();
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ void handle_vchan_error(const char *op)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_exec(const char *cmd __attribute__((__unused__))) {
|
void do_exec(char *cmd __attribute__((__unused__))) {
|
||||||
fprintf(stderr, "BUG: do_exec function shouldn't be called!\n");
|
fprintf(stderr, "BUG: do_exec function shouldn't be called!\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -33,19 +33,19 @@
|
|||||||
#include "libqrexec-utils.h"
|
#include "libqrexec-utils.h"
|
||||||
#include "qrexec-agent.h"
|
#include "qrexec-agent.h"
|
||||||
|
|
||||||
void do_exec(const char *cmd)
|
extern char **environ;
|
||||||
|
|
||||||
|
void do_exec(char *cmd)
|
||||||
{
|
{
|
||||||
char *shell;
|
char *shell;
|
||||||
char buf[strlen(QUBES_RPC_MULTIPLEXER_PATH) + strlen(cmd) - strlen(RPC_REQUEST_COMMAND) + 1];
|
|
||||||
/* replace magic RPC cmd with RPC multiplexer path */
|
|
||||||
if (strncmp(cmd, RPC_REQUEST_COMMAND " ", strlen(RPC_REQUEST_COMMAND)+1)==0) {
|
|
||||||
strcpy(buf, QUBES_RPC_MULTIPLEXER_PATH);
|
|
||||||
strcpy(buf + strlen(QUBES_RPC_MULTIPLEXER_PATH), cmd + strlen(RPC_REQUEST_COMMAND));
|
|
||||||
cmd = buf;
|
|
||||||
}
|
|
||||||
signal(SIGCHLD, SIG_DFL);
|
signal(SIGCHLD, SIG_DFL);
|
||||||
signal(SIGPIPE, SIG_DFL);
|
signal(SIGPIPE, SIG_DFL);
|
||||||
|
|
||||||
|
/* call QUBESRPC if requested */
|
||||||
|
exec_qubes_rpc_if_requested(cmd, environ);
|
||||||
|
|
||||||
|
/* otherwise, pass it to shell */
|
||||||
shell = getenv("SHELL");
|
shell = getenv("SHELL");
|
||||||
if (!shell)
|
if (!shell)
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
|
Loading…
Reference in New Issue
Block a user