Skip to content
This repository was archived by the owner on Sep 30, 2022. It is now read-only.

Commit aa9c643

Browse files
committed
pmix2x: sec/native: fix the pmix_native module under solaris by using getpeerucred()
and fail with a user friendly message if no method is available: "sec: native cannot validate_cred on this system" (back-ported from upstream openpmix/openpmix@c474a1f) (back-ported from commit open-mpi/ompi@c11e816)
1 parent 9ce4403 commit aa9c643

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

opal/mca/pmix/pmix112/pmix/config/pmix.m4

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dnl reserved.
1818
dnl Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved.
1919
dnl Copyright (c) 2011-2013 NVIDIA Corporation. All rights reserved.
2020
dnl Copyright (c) 2013-2015 Intel, Inc. All rights reserved
21-
dnl Copyright (c) 2015 Research Organization for Information Science
21+
dnl Copyright (c) 2015-2016 Research Organization for Information Science
2222
dnl and Technology (RIST). All rights reserved.
2323
dnl Copyright (c) 2016 Mellanox Technologies, Inc.
2424
dnl All rights reserved.
@@ -318,7 +318,8 @@ AC_DEFUN([PMIX_SETUP_CORE],[
318318
sys/wait.h syslog.h \
319319
time.h unistd.h \
320320
crt_externs.h signal.h \
321-
ioLib.h sockLib.h hostLib.h limits.h])
321+
ioLib.h sockLib.h hostLib.h limits.h \
322+
ucred.h])
322323

323324
# Note that sometimes we have <stdbool.h>, but it doesn't work (e.g.,
324325
# have both Portland and GNU installed; using pgcc will find GNU's
@@ -495,7 +496,7 @@ AC_DEFUN([PMIX_SETUP_CORE],[
495496
# Darwin doesn't need -lm, as it's a symlink to libSystem.dylib
496497
PMIX_SEARCH_LIBS_CORE([ceil], [m])
497498

498-
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep getpeereid])
499+
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep getpeereid getpeerucred])
499500

500501
# On some hosts, htonl is a define, so the AC_CHECK_FUNC will get
501502
# confused. On others, it's in the standard library, but stubbed with

opal/mca/pmix/pmix112/pmix/src/sec/pmix_native.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/*
22
* Copyright (c) 2015 Intel, Inc. All rights reserved.
33
* Copyright (c) 2016 IBM Corporation. All rights reserved.
4+
* Copyright (c) 2016 Research Organization for Information Science
5+
* and Technology (RIST). All rights reserved.
6+
*
47
* $COPYRIGHT$
58
*
69
* Additional copyrights may follow
@@ -22,6 +25,9 @@
2225
#ifdef HAVE_SYS_TYPES_H
2326
#include <sys/types.h>
2427
#endif
28+
#ifdef HAVE_UCRED_H
29+
#include <ucred.h>
30+
#endif
2531

2632
#include "pmix_sec.h"
2733
#include "pmix_native.h"
@@ -63,6 +69,9 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred)
6369
struct ucred ucred;
6470
#endif
6571
socklen_t crlen = sizeof (ucred);
72+
#endif
73+
#ifdef HAVE_GETPEERUCRED
74+
ucred_t *ucred = NULL;
6675
#endif
6776
uid_t euid;
6877
gid_t gid;
@@ -97,7 +106,24 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred)
97106
strerror (pmix_socket_errno));
98107
return PMIX_ERR_INVALID_CRED;
99108
}
109+
#elif defined(HAVE_GETPEERUCRED)
110+
pmix_output_verbose(2, pmix_globals.debug_output,
111+
"sec:native checking getpeerucred for peer credentials");
112+
if (0 != getpeerucred(peer->sd, &ucred)) {
113+
pmix_output_verbose(2, pmix_globals.debug_output,
114+
"sec: getsockopt getpeerucred failed: %s",
115+
strerror (pmix_socket_errno));
116+
pmix_output_verbose(2, pmix_globals.debug_output,
117+
"sec: getsockopt getpeerucred failed: %s",
118+
strerror (errno));
119+
return PMIX_ERR_INVALID_CRED;
120+
}
121+
euid = ucred_geteuid(ucred);
122+
gid = ucred_getrgid(ucred);
123+
ucred_free(ucred);
100124
#else
125+
pmix_output_verbose(2, pmix_globals.debug_output,
126+
"sec: native cannot validate_cred on this system");
101127
return PMIX_ERR_NOT_SUPPORTED;
102128
#endif
103129

0 commit comments

Comments
 (0)