|
1 | 1 | /* |
2 | 2 | * Copyright (c) 2015-2016 Intel, Inc. All rights reserved. |
3 | 3 | * Copyright (c) 2016 IBM Corporation. All rights reserved. |
| 4 | + * Copyright (c) 2016 Research Organization for Information Science |
| 5 | + * and Technology (RIST). All rights reserved. |
4 | 6 | * |
5 | 7 | * $COPYRIGHT$ |
6 | 8 | * |
|
24 | 26 | #ifdef HAVE_SYS_TYPES_H |
25 | 27 | #include <sys/types.h> |
26 | 28 | #endif |
| 29 | +#ifdef HAVE_UCRED_H |
| 30 | +#include <ucred.h> |
| 31 | +#endif |
27 | 32 |
|
28 | 33 | #include "pmix_sec.h" |
29 | 34 | #include "pmix_native.h" |
@@ -65,6 +70,9 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred) |
65 | 70 | struct ucred ucred; |
66 | 71 | #endif |
67 | 72 | socklen_t crlen = sizeof (ucred); |
| 73 | +#endif |
| 74 | +#ifdef HAVE_GETPEERUCRED |
| 75 | + ucred_t *ucred = NULL; |
68 | 76 | #endif |
69 | 77 | uid_t euid; |
70 | 78 | gid_t gid; |
@@ -99,7 +107,24 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred) |
99 | 107 | strerror (pmix_socket_errno)); |
100 | 108 | return PMIX_ERR_INVALID_CRED; |
101 | 109 | } |
| 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); |
102 | 125 | #else |
| 126 | + pmix_output_verbose(2, pmix_globals.debug_output, |
| 127 | + "sec: native cannot validate_cred on this system"); |
103 | 128 | return PMIX_ERR_NOT_SUPPORTED; |
104 | 129 | #endif |
105 | 130 |
|
|
0 commit comments