File: peerinfo.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (32 lines) | stat: -rw-r--r-- 586 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * Unix: wrapper for getsockopt(SO_PEERCRED), conditionalised on
 * appropriate autoconfery.
 */

#if HAVE_CMAKE_H
#include "cmake.h"
#endif

#if HAVE_SO_PEERCRED
#define _GNU_SOURCE
#include <features.h>
#endif

#include <sys/socket.h>

#include "putty.h"

bool so_peercred(int fd, int *pid, int *uid, int *gid)
{
#if HAVE_SO_PEERCRED
    struct ucred cr;
    socklen_t crlen = sizeof(cr);
    if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &crlen) == 0) {
        *pid = cr.pid;
        *uid = cr.uid;
        *gid = cr.gid;
        return true;
    }
#endif
    return false;
}