diff --git a/qrexec/qrexec.h b/qrexec/qrexec.h index 09a25254..a0f67565 100644 --- a/qrexec/qrexec.h +++ b/qrexec/qrexec.h @@ -31,6 +31,7 @@ enum { MSG_CLIENT_TO_SERVER_EXEC_CMDLINE = 0x100, MSG_CLIENT_TO_SERVER_JUST_EXEC, + MSG_CLIENT_TO_SERVER_CONNECT_EXISTING, MSG_SERVER_TO_AGENT_CONNECT_EXISTING, MSG_SERVER_TO_AGENT_EXEC_CMDLINE, diff --git a/qrexec/qrexec_client.c b/qrexec/qrexec_client.c index c378a550..e22fde3d 100644 --- a/qrexec/qrexec_client.c +++ b/qrexec/qrexec_client.c @@ -209,8 +209,9 @@ void select_loop(int s) void usage(char *name) { fprintf(stderr, - "usage: %s -d domain_num [-l local_prog] -e remote_cmdline\n" - "-e means exit after sending cmd\n", name); + "usage: %s -d domain_num [-l local_prog] -e -c remote_cmdline\n" + "-e means exit after sending cmd, -c: connect to existing process\n", + name); exit(1); } @@ -220,6 +221,7 @@ int main(int argc, char **argv) char *domname = NULL; int s; int just_exec = 0; + int connect_existing = 0; char *local_cmdline = NULL; while ((opt = getopt(argc, argv, "d:l:e")) != -1) { switch (opt) { @@ -232,6 +234,9 @@ int main(int argc, char **argv) case 'e': just_exec = 1; break; + case 'c': + connect_existing = 1; + break; default: usage(argv[0]); } @@ -247,8 +252,12 @@ int main(int argc, char **argv) send_cmdline(s, MSG_CLIENT_TO_SERVER_JUST_EXEC, argv[optind]); else { - send_cmdline(s, MSG_CLIENT_TO_SERVER_EXEC_CMDLINE, - argv[optind]); + int cmd; + if (connect_existing) + cmd = MSG_CLIENT_TO_SERVER_CONNECT_EXISTING; + else + cmd = MSG_CLIENT_TO_SERVER_EXEC_CMDLINE; + send_cmdline(s, cmd, argv[optind]); select_loop(s); } return 0; diff --git a/qrexec/qrexec_daemon.c b/qrexec/qrexec_daemon.c index 142369ec..5a56e6ff 100644 --- a/qrexec/qrexec_daemon.c +++ b/qrexec/qrexec_daemon.c @@ -211,6 +211,9 @@ void handle_cmdline_message_from_client(int fd) case MSG_CLIENT_TO_SERVER_JUST_EXEC: s_hdr.type = MSG_SERVER_TO_AGENT_JUST_EXEC; break; + case MSG_CLIENT_TO_SERVER_CONNECT_EXISTING: + s_hdr.type = MSG_SERVER_TO_AGENT_CONNECT_EXISTING; + break; default: terminate_client_and_flush_data(fd); return;