diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2022-03-08 11:35:06 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2022-03-08 11:35:06 +0000 |
commit | 04952f15df1bc81d1878833533d344a6b1d1326c (patch) | |
tree | 595f503d9c57ebb27774221465924f867bd35229 | |
parent | 9ed1226a66ee7e097ef858f7bc4b992fbcda2dc7 (diff) | |
download | rtmux-04952f15df1bc81d1878833533d344a6b1d1326c.tar.gz rtmux-04952f15df1bc81d1878833533d344a6b1d1326c.tar.bz2 rtmux-04952f15df1bc81d1878833533d344a6b1d1326c.zip |
Use getpeerucred if available (not tested).
-rw-r--r-- | compat/getpeereid.c | 19 | ||||
-rw-r--r-- | configure.ac | 6 |
2 files changed, 23 insertions, 2 deletions
diff --git a/compat/getpeereid.c b/compat/getpeereid.c index 722f14a2..5a593c07 100644 --- a/compat/getpeereid.c +++ b/compat/getpeereid.c @@ -19,6 +19,10 @@ #include <stdio.h> +#ifdef HAVE_UCRED_H +#include <ucred.h> +#endif + #include "compat.h" int @@ -33,6 +37,21 @@ getpeereid(int s, uid_t *uid, gid_t *gid) *uid = uc.uid; *gid = uc.gid; return (0); +#elif defined(HAVE_GETPEERUCRED) +int +getpeereid(int s, uid_t *uid, gid_t *gid) +{ + ucred_t *ucred = NULL; + + if (getpeerucred(s, &ucred) == -1) + return (-1); + if ((*uid = ucred_geteuid(ucred)) == -1) + return (-1); + if ((*gid = ucred_getrgid(ucred)) == -1) + return (-1); + ucred_free(ucred); + return (0); +} #else errno = EOPNOTSUPP; return (-1); diff --git a/configure.ac b/configure.ac index 6ca86ea4..e473f141 100644 --- a/configure.ac +++ b/configure.ac @@ -128,6 +128,7 @@ AC_CHECK_HEADERS([ \ sys/dir.h \ sys/ndir.h \ sys/tree.h \ + ucred.h \ util.h \ ]) @@ -146,7 +147,8 @@ AC_CHECK_FUNCS([ \ flock \ prctl \ proc_pidinfo \ - sysconf + getpeerucred \ + sysconf \ ]) # Check for functions with a compatibility implementation. @@ -170,7 +172,7 @@ AC_REPLACE_FUNCS([ \ strlcat \ strlcpy \ strndup \ - strsep + strsep \ ]) AC_FUNC_STRNLEN |