Skip to content

Commit c11e816

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)
1 parent e91292a commit c11e816

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

opal/mca/pmix/pmix2x/pmix/config/pmix.m4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ AC_DEFUN([PMIX_SETUP_CORE],[
302302
crt_externs.h signal.h \
303303
ioLib.h sockLib.h hostLib.h limits.h \
304304
sys/statfs.h sys/statvfs.h \
305-
netdb.h])
305+
netdb.h ucred.h])
306306

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

511-
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep statfs statvfs getpeereid strnlen])
511+
AC_CHECK_FUNCS([asprintf snprintf vasprintf vsnprintf strsignal socketpair strncpy_s usleep statfs statvfs getpeereid getpeerucred strnlen])
512512

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

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* Copyright (c) 2015-2016 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.
46
*
57
* $COPYRIGHT$
68
*
@@ -24,6 +26,9 @@
2426
#ifdef HAVE_SYS_TYPES_H
2527
#include <sys/types.h>
2628
#endif
29+
#ifdef HAVE_UCRED_H
30+
#include <ucred.h>
31+
#endif
2732

2833
#include "pmix_sec.h"
2934
#include "pmix_native.h"
@@ -65,6 +70,9 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred)
6570
struct ucred ucred;
6671
#endif
6772
socklen_t crlen = sizeof (ucred);
73+
#endif
74+
#ifdef HAVE_GETPEERUCRED
75+
ucred_t *ucred = NULL;
6876
#endif
6977
uid_t euid;
7078
gid_t gid;
@@ -99,7 +107,24 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred)
99107
strerror (pmix_socket_errno));
100108
return PMIX_ERR_INVALID_CRED;
101109
}
110+
#elif defined(HAVE_GETPEERUCRED)
111+
pmix_output_verbose(2, pmix_globals.debug_output,
112+
"sec:native checking getpeerucred for peer credentials");
113+
if (0 != getpeerucred(peer->sd, &ucred)) {
114+
pmix_output_verbose(2, pmix_globals.debug_output,
115+
"sec: getsockopt getpeerucred failed: %s",
116+
strerror (pmix_socket_errno));
117+
pmix_output_verbose(2, pmix_globals.debug_output,
118+
"sec: getsockopt getpeerucred failed: %s",
119+
strerror (errno));
120+
return PMIX_ERR_INVALID_CRED;
121+
}
122+
euid = ucred_geteuid(ucred);
123+
gid = ucred_getrgid(ucred);
124+
ucred_free(ucred);
102125
#else
126+
pmix_output_verbose(2, pmix_globals.debug_output,
127+
"sec: native cannot validate_cred on this system");
103128
return PMIX_ERR_NOT_SUPPORTED;
104129
#endif
105130

0 commit comments

Comments
 (0)