qrexec: move daemon-specific code out of unix_server.c
So that agent can use code in unix_server.c
This commit is contained in:
parent
60a435eb1e
commit
732a90443e
@ -32,7 +32,7 @@ int write_all_vchan_ext(void *buf, int size);
|
|||||||
int buffer_space_vchan_ext();
|
int buffer_space_vchan_ext();
|
||||||
void fix_fds(int fdin, int fdout, int fderr);
|
void fix_fds(int fdin, int fdout, int fderr);
|
||||||
|
|
||||||
int get_server_socket(int domid, char * domname);
|
int get_server_socket(char *);
|
||||||
int do_accept(int s);
|
int do_accept(int s);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <ioall.h>
|
#include <ioall.h>
|
||||||
|
#include <string.h>
|
||||||
#include "qrexec.h"
|
#include "qrexec.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "glue.h"
|
#include "glue.h"
|
||||||
@ -67,6 +68,21 @@ void sigchld_handler(int x);
|
|||||||
|
|
||||||
char *remote_domain_name; // guess what
|
char *remote_domain_name; // guess what
|
||||||
|
|
||||||
|
int create_qrexec_socket(int domid, char *domname)
|
||||||
|
{
|
||||||
|
char socket_address[40];
|
||||||
|
char link_to_socket_name[strlen(domname) + sizeof(socket_address)];
|
||||||
|
|
||||||
|
snprintf(socket_address, sizeof(socket_address),
|
||||||
|
QREXEC_DAEMON_SOCKET_DIR "/qrexec.%d", domid);
|
||||||
|
snprintf(link_to_socket_name, sizeof link_to_socket_name,
|
||||||
|
QREXEC_DAEMON_SOCKET_DIR "/qrexec.%s", domname);
|
||||||
|
unlink(link_to_socket_name);
|
||||||
|
symlink(socket_address, link_to_socket_name);
|
||||||
|
return get_server_socket(socket_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* do the preparatory tasks, needed before entering the main event loop */
|
/* do the preparatory tasks, needed before entering the main event loop */
|
||||||
void init(int xid)
|
void init(int xid)
|
||||||
{
|
{
|
||||||
@ -119,7 +135,7 @@ void init(int xid)
|
|||||||
/* 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 =
|
qrexec_daemon_unix_socket_fd =
|
||||||
get_server_socket(xid, remote_domain_name);
|
create_qrexec_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);
|
||||||
@ -167,8 +183,7 @@ 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,
|
void get_cmdline_body_from_client_and_pass_to_agent(int fd, struct server_header
|
||||||
struct server_header
|
|
||||||
*s_hdr)
|
*s_hdr)
|
||||||
{
|
{
|
||||||
int len = s_hdr->len;
|
int len = s_hdr->len;
|
||||||
@ -271,8 +286,7 @@ 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,
|
void get_packet_data_from_agent_and_pass_to_client(int client_id, struct client_header
|
||||||
struct client_header
|
|
||||||
*hdr)
|
*hdr)
|
||||||
{
|
{
|
||||||
int len = hdr->len;
|
int len = hdr->len;
|
||||||
|
@ -27,20 +27,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "qrexec.h"
|
#include "qrexec.h"
|
||||||
|
|
||||||
int get_server_socket(int domid, char *domname)
|
int get_server_socket(char *socket_address)
|
||||||
{
|
{
|
||||||
struct sockaddr_un sockname;
|
struct sockaddr_un sockname;
|
||||||
int s;
|
int s;
|
||||||
char socket_address[40];
|
|
||||||
char link_to_socket_name[strlen(domname) + sizeof(socket_address)];
|
|
||||||
|
|
||||||
snprintf(socket_address, sizeof(socket_address),
|
|
||||||
QREXEC_DAEMON_SOCKET_DIR "/qrexec.%d", domid);
|
|
||||||
snprintf(link_to_socket_name, sizeof link_to_socket_name,
|
|
||||||
QREXEC_DAEMON_SOCKET_DIR "/qrexec.%s", domname);
|
|
||||||
unlink(socket_address);
|
unlink(socket_address);
|
||||||
unlink(link_to_socket_name);
|
|
||||||
symlink(socket_address, link_to_socket_name);
|
|
||||||
|
|
||||||
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
s = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
memset(&sockname, 0, sizeof(sockname));
|
memset(&sockname, 0, sizeof(sockname));
|
||||||
|
Loading…
Reference in New Issue
Block a user