5353#include "src/util/argv.h"
5454#include "src/util/error.h"
5555#include "src/util/fd.h"
56+ #include "src/util/getid.h"
5657#include "src/util/output.h"
5758#include "src/util/pmix_environ.h"
5859#include "src/util/progress_threads.h"
@@ -73,7 +74,7 @@ static pthread_t engine;
7374/*
7475 * start listening on our rendezvous file
7576 */
76- pmix_status_t pmix_start_listening (pmix_listener_t * lt )
77+ pmix_status_t pmix_prepare_listening (pmix_listener_t * lt , bool * need_listener )
7778{
7879 int flags ;
7980 pmix_status_t rc ;
@@ -95,7 +96,6 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt)
9596 }
9697
9798
98-
9999 addrlen = sizeof (struct sockaddr_un );
100100 if (bind (lt -> socket , (struct sockaddr * )address , addrlen ) < 0 ) {
101101 printf ("%s:%d bind() failed\n" , __FILE__ , __LINE__ );
@@ -137,16 +137,18 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt)
137137 goto sockerror ;
138138 }
139139
140- /* setup my version for validating connections - we
141- * only check the major version numbers */
142- myversion = strdup (PMIX_VERSION );
143- /* find the first '.' */
144- ptr = strchr (myversion , '.' );
145- if (NULL != ptr ) {
146- ++ ptr ;
147- /* stop it at the second '.', if present */
148- if (NULL != (ptr = strchr (ptr , '.' ))) {
149- * ptr = '\0' ;
140+ if (NULL == myversion ) {
141+ /* setup my version for validating connections - we
142+ * only check the major version numbers */
143+ myversion = strdup (PMIX_VERSION );
144+ /* find the first '.' */
145+ ptr = strchr (myversion , '.' );
146+ if (NULL != ptr ) {
147+ ++ ptr ;
148+ /* stop it at the second '.', if present */
149+ if (NULL != (ptr = strchr (ptr , '.' ))) {
150+ * ptr = '\0' ;
151+ }
150152 }
151153 }
152154
@@ -157,27 +159,7 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt)
157159 }
158160
159161 if (PMIX_SUCCESS != rc && !pmix_server_globals .listen_thread_active ) {
160- /*** spawn internal listener thread */
161- if (0 > pipe (pmix_server_globals .stop_thread )) {
162- PMIX_ERROR_LOG (PMIX_ERR_IN_ERRNO );
163- return PMIX_ERR_OUT_OF_RESOURCE ;
164- }
165- /* Make sure the pipe FDs are set to close-on-exec so that
166- they don't leak into children */
167- if (pmix_fd_set_cloexec (pmix_server_globals .stop_thread [0 ]) != PMIX_SUCCESS ||
168- pmix_fd_set_cloexec (pmix_server_globals .stop_thread [1 ]) != PMIX_SUCCESS ) {
169- PMIX_ERROR_LOG (PMIX_ERR_IN_ERRNO );
170- close (pmix_server_globals .stop_thread [0 ]);
171- close (pmix_server_globals .stop_thread [1 ]);
172- return PMIX_ERR_OUT_OF_RESOURCE ;
173- }
174- /* fork off the listener thread */
175- if (0 > pthread_create (& engine , NULL , listen_thread , NULL )) {
176- pmix_server_globals .listen_thread_active = false;
177- return PMIX_ERROR ;
178- } else {
179- pmix_server_globals .listen_thread_active = true;
180- }
162+ * need_listener = true;
181163 }
182164
183165 return PMIX_SUCCESS ;
@@ -188,6 +170,31 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt)
188170 return PMIX_ERROR ;
189171}
190172
173+ pmix_status_t pmix_start_listening (void ) {
174+ /*** spawn internal listener thread */
175+ if (0 > pipe (pmix_server_globals .stop_thread )) {
176+ PMIX_ERROR_LOG (PMIX_ERR_IN_ERRNO );
177+ return PMIX_ERR_OUT_OF_RESOURCE ;
178+ }
179+ /* Make sure the pipe FDs are set to close-on-exec so that
180+ they don't leak into children */
181+ if (pmix_fd_set_cloexec (pmix_server_globals .stop_thread [0 ]) != PMIX_SUCCESS ||
182+ pmix_fd_set_cloexec (pmix_server_globals .stop_thread [1 ]) != PMIX_SUCCESS ) {
183+ PMIX_ERROR_LOG (PMIX_ERR_IN_ERRNO );
184+ close (pmix_server_globals .stop_thread [0 ]);
185+ close (pmix_server_globals .stop_thread [1 ]);
186+ return PMIX_ERR_OUT_OF_RESOURCE ;
187+ }
188+ /* fork off the listener thread */
189+ pmix_server_globals .listen_thread_active = true;
190+ if (0 > pthread_create (& engine , NULL , listen_thread , NULL )) {
191+ pmix_server_globals .listen_thread_active = false;
192+ return PMIX_ERROR ;
193+ }
194+
195+ return PMIX_SUCCESS ;
196+ }
197+
191198void pmix_stop_listening (void )
192199{
193200 int i ;
@@ -533,6 +540,8 @@ static pmix_status_t pmix_server_authenticate(pmix_pending_connection_t *pnd,
533540 pmix_peer_t * psave = NULL ;
534541 bool found ;
535542 pmix_proc_t proc ;
543+ uid_t uid ;
544+ gid_t gid ;
536545
537546 pmix_output_verbose (2 , pmix_globals .debug_output ,
538547 "RECV CONNECT ACK FROM PEER ON SOCKET %d" ,
@@ -720,9 +729,24 @@ static pmix_status_t pmix_server_authenticate(pmix_pending_connection_t *pnd,
720729 }
721730 }
722731 } else {
732+ /* get the tool socket's uid and gid so we can pass them to
733+ * the host RM for validation */
734+ if (PMIX_SUCCESS != (rc = pmix_util_getid (pnd -> sd , & uid , & gid ))) {
735+ return rc ;
736+ }
737+ /* we pass this info in an array of pmix_info_t structs,
738+ * so set that up here */
739+ pnd -> ninfo = 2 ;
740+ PMIX_INFO_CREATE (pnd -> info , pnd -> ninfo );
741+ (void )strncpy (pnd -> info [0 ].key , PMIX_USERID , PMIX_MAX_KEYLEN );
742+ pnd -> info [0 ].value .type = PMIX_UINT32 ;
743+ pnd -> info [0 ].value .data .uint32 = uid ;
744+ (void )strncpy (pnd -> info [1 ].key , PMIX_GRPID , PMIX_MAX_KEYLEN );
745+ pnd -> info [0 ].value .type = PMIX_UINT32 ;
746+ pnd -> info [0 ].value .data .uint32 = gid ;
723747 /* request an nspace for this requestor - it will
724748 * automatically be assigned rank=0 */
725- pmix_host_server .tool_connected (NULL , 0 , cnct_cbfunc , pnd );
749+ pmix_host_server .tool_connected (pnd -> info , pnd -> ninfo , cnct_cbfunc , pnd );
726750 return PMIX_ERR_OPERATION_IN_PROGRESS ;
727751 }
728752 return rc ;
@@ -799,7 +823,6 @@ static void tool_handler(int sd, short flags, void* cbdata)
799823
800824 /* initiate the authentication handshake */
801825 if (PMIX_ERR_OPERATION_IN_PROGRESS != pmix_server_authenticate (pnd , NULL , NULL )) {
802- pmix_output (0 , "SHOOT" );
803826 CLOSE_THE_SOCKET (pnd -> sd );
804827 PMIX_RELEASE (pnd );
805828 }
0 commit comments