Skip to content

Commit 584532b

Browse files
committed
Use LOCAL_PEERCRED option instead SO_PEERCRED where appropriate
1 parent debf110 commit 584532b

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

src/responder/common/responder_common.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ static errno_t get_client_cred(struct cli_ctx *cctx)
112112
cctx->creds->ucred.gid = -1;
113113
cctx->creds->ucred.pid = -1;
114114

115-
ret = getsockopt(cctx->cfd, SOL_SOCKET, SO_PEERCRED, &cctx->creds->ucred,
115+
ret = getsockopt(cctx->cfd, SOL_SOCKET, SSS_PEERCRED_SOCKET_OPTION,
116+
&cctx->creds->ucred,
116117
&client_cred_len);
117118
if (ret != EOK) {
118119
ret = errno;

src/sss_client/common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ static errno_t check_server_cred(int sockfd)
10341034
return EFAULT;
10351035
}
10361036

1037-
ret = getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &server_cred,
1037+
ret = getsockopt(sockfd, SOL_SOCKET, SSS_PEERCRED_SOCKET_OPTION, &server_cred,
10381038
&server_cred_len);
10391039
if (ret != 0) {
10401040
return errno;

src/tests/intg/getsockopt_wrapper.c

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <fcntl.h>
1515
#include <unistd.h>
1616

17+
#if !defined(SO_PEERCRED) && defined(LOCAL_PEERCRED)
18+
#define SO_PEERCRED LOCAL_PEERCRED
19+
#endif
20+
1721
static bool is_dbus_socket(int fd)
1822
{
1923
int ret;

src/util/util_creds.h

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef void * SEC_CTX;
6464
#endif /* done HAVE_SELINUX */
6565

6666
#ifdef HAVE_UCRED
67+
#define SSS_PEERCRED_SOCKET_OPTION SO_PEERCRED
6768
#define STRUCT_CRED struct ucred
6869
#define CRED_UID(x) ((x)->uid)
6970
#define CRED_GID(x) ((x)->gid)
@@ -76,6 +77,7 @@ typedef void * SEC_CTX;
7677
* page: https://man.freebsd.org/cgi/man.cgi?query=unix
7778
*/
7879
#define STRUCT_CRED struct xucred
80+
#define SSS_PEERCRED_SOCKET_OPTION LOCAL_PEERCRED
7981
#define CRED_UID(x) ((x)->cr_uid)
8082
#define CRED_GID(x) ((x)->cr_ngroups > 0 ? (x)->cr_groups[0] : -1)
8183
#define CRED_PID(x) ((x)->cr_pid)

0 commit comments

Comments
 (0)