peerinfo.c 586 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Unix: wrapper for getsockopt(SO_PEERCRED), conditionalised on
  3. * appropriate autoconfery.
  4. */
  5. #if HAVE_CMAKE_H
  6. #include "cmake.h"
  7. #endif
  8. #if HAVE_SO_PEERCRED
  9. #define _GNU_SOURCE
  10. #include <features.h>
  11. #endif
  12. #include <sys/socket.h>
  13. #include "putty.h"
  14. bool so_peercred(int fd, int *pid, int *uid, int *gid)
  15. {
  16. #if HAVE_SO_PEERCRED
  17. struct ucred cr;
  18. socklen_t crlen = sizeof(cr);
  19. if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crlen) == 0) {
  20. *pid = cr.pid;
  21. *uid = cr.uid;
  22. *gid = cr.gid;
  23. return true;
  24. }
  25. #endif
  26. return false;
  27. }