No description
Find a file
Renovate d3aa00df76
All checks were successful
Go check / check-go (push) Successful in 40s
fix(deps): update module golang.org/x/sys to v0.39.0 (#27)
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| golang.org/x/sys | `v0.38.0` -> `v0.39.0` | ![age](https://developer.mend.io/api/mc/badges/age/go/golang.org%2fx%2fsys/v0.39.0?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/golang.org%2fx%2fsys/v0.38.0/v0.39.0?slim=true) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4yNy4xIiwidXBkYXRlZEluVmVyIjoiNDIuMjcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Reviewed-on: #27
Co-authored-by: Renovate <renovate@foxden.network>
Co-committed-by: Renovate <renovate@foxden.network>
2025-12-08 09:08:59 -08:00
.forgejo/workflows chore(reposyncer): update repo baseline (#26) 2025-11-28 23:44:38 -08:00
go.mod fix(deps): update module golang.org/x/sys to v0.39.0 (#27) 2025-12-08 09:08:59 -08:00
go.sum fix(deps): update module golang.org/x/sys to v0.39.0 (#27) 2025-12-08 09:08:59 -08:00
LICENSE initial commit 2020-09-27 13:37:27 -04:00
peercred.go initial commit 2020-09-27 13:37:27 -04:00
peercred_linux.go initial commit 2020-09-27 13:37:27 -04:00
peercred_linux_test.go Fix lint 2025-11-14 12:18:56 -08:00
peercred_unsupported.go Fix lint 2025-11-14 12:18:56 -08:00
peercred_unsupported_test.go Fix lint 2025-11-14 12:18:56 -08:00
README.md initial commit 2020-09-27 13:37:27 -04:00
renovate.json chore(reposyncer): update repo baseline (#23) 2025-11-16 20:48:21 -08:00

peercred

peercred is a Go package that wraps usage of the Linux SO_PEERCRED socket option on Unix domain sockets.

From the unix(7) man page:

   SO_PEERCRED
          This read-only socket option returns the credentials of the
          peer process connected to this socket.  The returned creden
          tials are those that were in effect at the time of the call to
          connect(2) or socketpair(2).

          The argument to getsockopt(2) is a pointer to a ucred struc
          ture; define the _GNU_SOURCE feature test macro to obtain the
          definition of that structure from <sys/socket.h>.

          The use of this option is possible only for connected AF_UNIX
          stream sockets and for AF_UNIX stream and datagram socket
          pairs created using socketpair(2).

On Linux systems, the raw functionality is provided through the built-in syscall package and the golang.org/x/sys/unix package. These packages, however, are not stable across operating systems and the usage of socket options is pretty low level. This package encapsulates the functionality and returns errors on unsupported operating systems through an easy Read function.

The returned value provides the process ID, user ID, and group ID of the process on the other side of the Unix domain socket. These values are populated by the Linux kernel and cannot be spoofed. (However, these values are set at the time of socket creation and will not take into account privileges dropped afterward.)

Usage


conn, err := net.Dial("unix", "/var/run/somesocket")
if err != nil {
    log.Fatal(err)
}

cred, err := peercred.Read(conn.(*net.UnixConn))
if err != nil {
    log.Fatal(err)
}

fmt.Printf("%+v\n", cred)
// => &{PID:2002 UID:1000 GID:1000}

License

Copyright 2020 Joe Shaw

peercred is licensed under the MIT license. See the LICENSE file for details.