|
1 | 1 | /* |
2 | 2 | * Copyright (c) 2015 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. |
| 6 | + * |
4 | 7 | * $COPYRIGHT$ |
5 | 8 | * |
6 | 9 | * Additional copyrights may follow |
|
22 | 25 | #ifdef HAVE_SYS_TYPES_H |
23 | 26 | #include <sys/types.h> |
24 | 27 | #endif |
| 28 | +#ifdef HAVE_UCRED_H |
| 29 | +#include <ucred.h> |
| 30 | +#endif |
25 | 31 |
|
26 | 32 | #include "pmix_sec.h" |
27 | 33 | #include "pmix_native.h" |
@@ -63,6 +69,9 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred) |
63 | 69 | struct ucred ucred; |
64 | 70 | #endif |
65 | 71 | socklen_t crlen = sizeof (ucred); |
| 72 | +#endif |
| 73 | +#ifdef HAVE_GETPEERUCRED |
| 74 | + ucred_t *ucred = NULL; |
66 | 75 | #endif |
67 | 76 | uid_t euid; |
68 | 77 | gid_t gid; |
@@ -97,7 +106,24 @@ static pmix_status_t validate_cred(pmix_peer_t *peer, char *cred) |
97 | 106 | strerror (pmix_socket_errno)); |
98 | 107 | return PMIX_ERR_INVALID_CRED; |
99 | 108 | } |
| 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); |
100 | 124 | #else |
| 125 | + pmix_output_verbose(2, pmix_globals.debug_output, |
| 126 | + "sec: native cannot validate_cred on this system"); |
101 | 127 | return PMIX_ERR_NOT_SUPPORTED; |
102 | 128 | #endif |
103 | 129 |
|
|
0 commit comments