@@ -85,6 +85,7 @@ static const char *fork_server_path = QREXEC_FORK_SERVER_SOCKET;
85
85
static void handle_server_exec_request_do (int type , int connect_domain , int connect_port ,
86
86
struct qrexec_parsed_command * cmd ,
87
87
char * cmdline );
88
+ static void terminate_connection (uint32_t domain , uint32_t port );
88
89
89
90
const bool qrexec_is_fork_server = false;
90
91
@@ -587,26 +588,20 @@ static void handle_server_exec_request_init(struct msg_header *hdr)
587
588
cmd = parse_qubes_rpc_command (buf , true);
588
589
if (cmd == NULL ) {
589
590
LOG (ERROR , "Could not parse command line: %s" , buf );
590
- return ;
591
+ goto doit ;
591
592
}
592
593
593
594
/* load service config only for service requests */
594
595
if (cmd -> service_descriptor ) {
595
- int wait_for_session = 0 ;
596
- char * user = NULL ;
597
-
598
- if (load_service_config (cmd , & wait_for_session , & user ) < 0 ) {
596
+ if (load_service_config_v2 (cmd ) < 0 ) {
599
597
LOG (ERROR , "Could not load config for command %s" , buf );
600
- return ;
601
- }
602
-
603
- if (user != NULL ) {
604
- free (cmd -> username );
605
- cmd -> username = user ;
598
+ destroy_qrexec_parsed_command (cmd );
599
+ cmd = NULL ;
600
+ goto doit ;
606
601
}
607
602
608
603
/* "nogui:" prefix has priority */
609
- if (!cmd -> nogui && wait_for_session && wait_for_session_maybe (cmd )) {
604
+ if (!cmd -> nogui && cmd -> wait_for_session && wait_for_session_maybe (cmd )) {
610
605
/* waiting for session, postpone actual call */
611
606
int slot_index ;
612
607
for (slot_index = 0 ; slot_index < MAX_FDS ; slot_index ++ )
@@ -628,6 +623,7 @@ static void handle_server_exec_request_init(struct msg_header *hdr)
628
623
}
629
624
}
630
625
626
+ doit :
631
627
handle_server_exec_request_do (hdr -> type , params .connect_domain , params .connect_port , cmd , buf );
632
628
destroy_qrexec_parsed_command (cmd );
633
629
free (buf );
@@ -671,7 +667,7 @@ static void handle_server_exec_request_do(int type,
671
667
return ;
672
668
}
673
669
674
- if (!cmd -> nogui ) {
670
+ if (cmd != NULL && !cmd -> nogui ) {
675
671
/* try fork server */
676
672
int child_socket = try_fork_server (type ,
677
673
params .connect_domain , params .connect_port ,
@@ -765,20 +761,29 @@ static int find_connection(int pid)
765
761
}
766
762
767
763
static void release_connection (int id ) {
768
- struct msg_header hdr ;
769
- struct exec_params params ;
770
-
771
- hdr .type = MSG_CONNECTION_TERMINATED ;
772
- hdr .len = sizeof (struct exec_params );
773
- params .connect_domain = connection_info [id ].connect_domain ;
774
- params .connect_port = connection_info [id ].connect_port ;
775
- if (libvchan_send (ctrl_vchan , & hdr , sizeof (hdr )) != sizeof (hdr ))
776
- handle_vchan_error ("send (MSG_CONNECTION_TERMINATED hdr)" );
777
- if (libvchan_send (ctrl_vchan , & params , sizeof (params )) != sizeof (params ))
778
- handle_vchan_error ("send (MSG_CONNECTION_TERMINATED data)" );
764
+ terminate_connection (connection_info [id ].connect_domain ,
765
+ connection_info [id ].connect_port );
779
766
connection_info [id ].pid = 0 ;
780
767
}
781
768
769
+ static void terminate_connection (uint32_t domain , uint32_t port ) {
770
+ struct {
771
+ struct msg_header hdr ;
772
+ struct exec_params params ;
773
+ } data = {
774
+ .hdr = {
775
+ .type = MSG_CONNECTION_TERMINATED ,
776
+ .len = sizeof (struct exec_params ),
777
+ },
778
+ .params = {
779
+ .connect_domain = domain ,
780
+ .connect_port = port ,
781
+ },
782
+ };
783
+ if (libvchan_send (ctrl_vchan , & data , sizeof (data )) != sizeof (data ))
784
+ handle_vchan_error ("send (MSG_CONNECTION_TERMINATED)" );
785
+ }
786
+
782
787
static void reap_children (void )
783
788
{
784
789
int status ;
0 commit comments