os: Use LOCAL_PEERPID from sys/un.h if it is available to detemine the pid when falling back on getpeereids()
This provides a way to determine the pid of a peer connection on
systems like darwin that do not support getpeerucred() nor
SO_PEERCRED.
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
(cherry picked from commit 8a4ab22873
)
This commit is contained in:
parent
a6c49106ce
commit
1317083fbc
|
@ -135,6 +135,7 @@ conf_data.set('HAVE_STRING_H', cc.has_header('string.h') ? '1' : false)
|
|||
conf_data.set('HAVE_STRINGS_H', cc.has_header('strings.h') ? '1' : false)
|
||||
conf_data.set('HAVE_SYS_AGPGART_H', cc.has_header('sys/agpgart.h') ? '1' : false)
|
||||
conf_data.set('HAVE_SYS_AGPIO_H', cc.has_header('sys/agpio.h') ? '1' : false)
|
||||
conf_data.set('HAVE_SYS_UN_H', cc.has_header('sys/un.h') ? '1' : false)
|
||||
conf_data.set('HAVE_SYS_UTSNAME_H', cc.has_header('sys/utsname.h') ? '1' : false)
|
||||
conf_data.set('HAVE_SYS_SYSMACROS_H', cc.has_header('sys/sysmacros.h') ? '1' : false)
|
||||
conf_data.set('HAVE_UNISTD_H', cc.has_header('unistd.h') ? '1' : false)
|
||||
|
|
18
os/access.c
18
os/access.c
|
@ -116,6 +116,10 @@ SOFTWARE.
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
|
||||
#if defined(SVR4) || (defined(SYSV) && defined(__i386__)) || defined(__GNU__)
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
@ -1176,6 +1180,10 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp)
|
|||
#elif defined(HAVE_GETPEEREID)
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
#if defined(LOCAL_PEERPID)
|
||||
pid_t pid;
|
||||
socklen_t so_len = sizeof(pid);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (client == NULL)
|
||||
|
@ -1253,6 +1261,16 @@ GetLocalClientCreds(ClientPtr client, LocalClientCredRec ** lccp)
|
|||
lcc->euid = uid;
|
||||
lcc->egid = gid;
|
||||
lcc->fieldsSet = LCC_UID_SET | LCC_GID_SET;
|
||||
|
||||
#if defined(LOCAL_PEERPID)
|
||||
if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERPID, &pid, &so_len) != 0) {
|
||||
ErrorF("getsockopt failed to determine pid of socket %d: %s\n", fd, strerror(errno));
|
||||
} else {
|
||||
lcc->pid = pid;
|
||||
lcc->fieldsSet |= LCC_PID_SET;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
#else
|
||||
|
|
Loading…
Reference in New Issue