qrexec - indentation

This commit is contained in:
Rafal Wojtczuk 2011-05-04 13:00:39 +02:00
parent b4fb7a4b5d
commit d84289f983
2 changed files with 45 additions and 31 deletions

View File

@ -195,8 +195,8 @@ void send_exit_code(int client_id, int status)
s_hdr.len = sizeof status; s_hdr.len = sizeof status;
write_all_vchan_ext(&s_hdr, sizeof s_hdr); write_all_vchan_ext(&s_hdr, sizeof s_hdr);
write_all_vchan_ext(&status, sizeof(status)); write_all_vchan_ext(&status, sizeof(status));
fprintf(stderr, "send exit code for client_id %d pid %d\n", client_id, fprintf(stderr, "send exit code for client_id %d pid %d\n",
client_info[client_id].pid); client_id, client_info[client_id].pid);
} }
@ -206,7 +206,8 @@ void remove_process(int client_id, int status)
int i; int i;
if (!client_info[client_id].pid) if (!client_info[client_id].pid)
return; return;
fork_and_flush_stdin(client_info[client_id].stdin_fd, &client_info[client_id].buffer); fork_and_flush_stdin(client_info[client_id].stdin_fd,
&client_info[client_id].buffer);
#if 0 #if 0
// let's let it die by itself, possibly after it has received buffered stdin // let's let it die by itself, possibly after it has received buffered stdin
kill(client_info[client_id].pid, SIGKILL); kill(client_info[client_id].pid, SIGKILL);
@ -242,7 +243,8 @@ void handle_input(int client_id, int len)
if (len == 0) { if (len == 0) {
if (client_info[client_id].is_blocked) if (client_info[client_id].is_blocked)
client_info[client_id].is_close_after_flush_needed = 1; client_info[client_id].
is_close_after_flush_needed = 1;
else { else {
close(client_info[client_id].stdin_fd); close(client_info[client_id].stdin_fd);
client_info[client_id].stdin_fd = -1; client_info[client_id].stdin_fd = -1;
@ -453,7 +455,8 @@ int fill_fds_for_select(fd_set * rdset, fd_set * wrset)
void flush_client_data_agent(int client_id) void flush_client_data_agent(int client_id)
{ {
struct _client_info *info = &client_info[client_id]; struct _client_info *info = &client_info[client_id];
switch (flush_client_data(info->stdin_fd, client_id, &info->buffer)) { switch (flush_client_data
(info->stdin_fd, client_id, &info->buffer)) {
case WRITE_STDIN_OK: case WRITE_STDIN_OK:
info->is_blocked = 0; info->is_blocked = 0;
if (info->is_close_after_flush_needed) { if (info->is_close_after_flush_needed) {
@ -486,7 +489,8 @@ void handle_trigger_io()
if (!strcmp(buf, "FCPR")) if (!strcmp(buf, "FCPR"))
s_hdr.client_id = QREXEC_EXECUTE_FILE_COPY; s_hdr.client_id = QREXEC_EXECUTE_FILE_COPY;
else if (!strcmp(buf, "DVMR")) else if (!strcmp(buf, "DVMR"))
s_hdr.client_id = QREXEC_EXECUTE_FILE_COPY_FOR_DISPVM; s_hdr.client_id =
QREXEC_EXECUTE_FILE_COPY_FOR_DISPVM;
if (s_hdr.client_id) { if (s_hdr.client_id) {
s_hdr.type = MSG_AGENT_TO_SERVER_TRIGGER_EXEC; s_hdr.type = MSG_AGENT_TO_SERVER_TRIGGER_EXEC;
write_all_vchan_ext(&s_hdr, sizeof s_hdr); write_all_vchan_ext(&s_hdr, sizeof s_hdr);

View File

@ -96,7 +96,9 @@ void init(int xid)
snprintf(qrexec_error_log_name, sizeof(qrexec_error_log_name), snprintf(qrexec_error_log_name, sizeof(qrexec_error_log_name),
"/var/log/qubes/qrexec.%d.log", xid); "/var/log/qubes/qrexec.%d.log", xid);
umask(0007); // make the log readable by the "qubes" group umask(0007); // make the log readable by the "qubes" group
logfd = open(qrexec_error_log_name, O_WRONLY | O_CREAT | O_TRUNC, 0640); logfd =
open(qrexec_error_log_name, O_WRONLY | O_CREAT | O_TRUNC,
0640);
if (logfd < 0) { if (logfd < 0) {
perror("open"); perror("open");
@ -116,7 +118,8 @@ void init(int xid)
setuid(getuid()); setuid(getuid());
/* When running as root, make the socket accessible; perms on /var/run/qubes still apply */ /* When running as root, make the socket accessible; perms on /var/run/qubes still apply */
umask(0); umask(0);
qrexec_daemon_unix_socket_fd = get_server_socket(xid, remote_domain_name); qrexec_daemon_unix_socket_fd =
get_server_socket(xid, remote_domain_name);
umask(0077); umask(0077);
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGCHLD, sigchld_handler); signal(SIGCHLD, sigchld_handler);
@ -164,7 +167,9 @@ void terminate_client_and_flush_data(int fd)
write_all_vchan_ext(&s_hdr, sizeof(s_hdr)); write_all_vchan_ext(&s_hdr, sizeof(s_hdr));
} }
void get_cmdline_body_from_client_and_pass_to_agent(int fd, struct server_header *s_hdr) void get_cmdline_body_from_client_and_pass_to_agent(int fd,
struct server_header
*s_hdr)
{ {
int len = s_hdr->len; int len = s_hdr->len;
char buf[len]; char buf[len];
@ -246,7 +251,8 @@ buffered data.
*/ */
void write_buffered_data_to_client(int client_id) void write_buffered_data_to_client(int client_id)
{ {
switch (flush_client_data(client_id, client_id, &clients[client_id].buffer)) { switch (flush_client_data
(client_id, client_id, &clients[client_id].buffer)) {
case WRITE_STDIN_OK: // no more buffered data case WRITE_STDIN_OK: // no more buffered data
clients[client_id].state &= ~CLIENT_OUTQ_FULL; clients[client_id].state &= ~CLIENT_OUTQ_FULL;
break; break;
@ -265,7 +271,9 @@ void write_buffered_data_to_client(int client_id)
The header (hdr argument) is already built. Just read the raw data from The header (hdr argument) is already built. Just read the raw data from
the packet, and pass it along with the header to the client. the packet, and pass it along with the header to the client.
*/ */
void get_packet_data_from_agent_and_pass_to_client(int client_id, struct client_header *hdr) void get_packet_data_from_agent_and_pass_to_client(int client_id,
struct client_header
*hdr)
{ {
int len = hdr->len; int len = hdr->len;
char buf[sizeof(*hdr) + len]; char buf[sizeof(*hdr) + len];
@ -380,7 +388,8 @@ void handle_execute_predefined_command(int req)
void check_client_id_in_range(unsigned int untrusted_client_id) void check_client_id_in_range(unsigned int untrusted_client_id)
{ {
if (untrusted_client_id >= MAX_CLIENTS || untrusted_client_id < 0) { if (untrusted_client_id >= MAX_CLIENTS || untrusted_client_id < 0) {
fprintf(stderr, "from agent: client_id=%d\n", untrusted_client_id); fprintf(stderr, "from agent: client_id=%d\n",
untrusted_client_id);
exit(1); exit(1);
} }
} }
@ -474,7 +483,8 @@ void handle_message_from_agent()
read_all_vchan_ext(buf, s_hdr.len); read_all_vchan_ext(buf, s_hdr.len);
return; return;
} }
get_packet_data_from_agent_and_pass_to_client(s_hdr.client_id, &hdr); get_packet_data_from_agent_and_pass_to_client(s_hdr.client_id,
&hdr);
if (s_hdr.type == MSG_AGENT_TO_SERVER_EXIT_CODE) if (s_hdr.type == MSG_AGENT_TO_SERVER_EXIT_CODE)
terminate_client_and_flush_data(s_hdr.client_id); terminate_client_and_flush_data(s_hdr.client_id);
} }