qrexec: CONNECT_EXISTING command handling in daemon and client

This commit is contained in:
Rafal Wojtczuk 2011-07-04 20:55:25 +02:00
parent c05b26763a
commit b4f28152b8
3 changed files with 17 additions and 4 deletions

View File

@ -31,6 +31,7 @@
enum { enum {
MSG_CLIENT_TO_SERVER_EXEC_CMDLINE = 0x100, MSG_CLIENT_TO_SERVER_EXEC_CMDLINE = 0x100,
MSG_CLIENT_TO_SERVER_JUST_EXEC, MSG_CLIENT_TO_SERVER_JUST_EXEC,
MSG_CLIENT_TO_SERVER_CONNECT_EXISTING,
MSG_SERVER_TO_AGENT_CONNECT_EXISTING, MSG_SERVER_TO_AGENT_CONNECT_EXISTING,
MSG_SERVER_TO_AGENT_EXEC_CMDLINE, MSG_SERVER_TO_AGENT_EXEC_CMDLINE,

View File

@ -209,8 +209,9 @@ void select_loop(int s)
void usage(char *name) void usage(char *name)
{ {
fprintf(stderr, fprintf(stderr,
"usage: %s -d domain_num [-l local_prog] -e remote_cmdline\n" "usage: %s -d domain_num [-l local_prog] -e -c remote_cmdline\n"
"-e means exit after sending cmd\n", name); "-e means exit after sending cmd, -c: connect to existing process\n",
name);
exit(1); exit(1);
} }
@ -220,6 +221,7 @@ int main(int argc, char **argv)
char *domname = NULL; char *domname = NULL;
int s; int s;
int just_exec = 0; int just_exec = 0;
int connect_existing = 0;
char *local_cmdline = NULL; char *local_cmdline = NULL;
while ((opt = getopt(argc, argv, "d:l:e")) != -1) { while ((opt = getopt(argc, argv, "d:l:e")) != -1) {
switch (opt) { switch (opt) {
@ -232,6 +234,9 @@ int main(int argc, char **argv)
case 'e': case 'e':
just_exec = 1; just_exec = 1;
break; break;
case 'c':
connect_existing = 1;
break;
default: default:
usage(argv[0]); usage(argv[0]);
} }
@ -247,8 +252,12 @@ int main(int argc, char **argv)
send_cmdline(s, MSG_CLIENT_TO_SERVER_JUST_EXEC, send_cmdline(s, MSG_CLIENT_TO_SERVER_JUST_EXEC,
argv[optind]); argv[optind]);
else { else {
send_cmdline(s, MSG_CLIENT_TO_SERVER_EXEC_CMDLINE, int cmd;
argv[optind]); 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); select_loop(s);
} }
return 0; return 0;

View File

@ -211,6 +211,9 @@ void handle_cmdline_message_from_client(int fd)
case MSG_CLIENT_TO_SERVER_JUST_EXEC: case MSG_CLIENT_TO_SERVER_JUST_EXEC:
s_hdr.type = MSG_SERVER_TO_AGENT_JUST_EXEC; s_hdr.type = MSG_SERVER_TO_AGENT_JUST_EXEC;
break; break;
case MSG_CLIENT_TO_SERVER_CONNECT_EXISTING:
s_hdr.type = MSG_SERVER_TO_AGENT_CONNECT_EXISTING;
break;
default: default:
terminate_client_and_flush_data(fd); terminate_client_and_flush_data(fd);
return; return;