mirror of
https://github.com/rwinkhart/peercred-mini.git
synced 2026-09-05 16:47:25 -04:00
Add support for solaris
This commit is contained in:
committed by
Brad Fitzpatrick
parent
6dd762fa3d
commit
35a0c7bd7e
@@ -2,4 +2,4 @@ module github.com/tailscale/peercred
|
|||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require golang.org/x/sys v0.0.0-20210301091718-77cc2087c03b
|
require golang.org/x/sys v0.29.1-0.20250107080300-1c14dcadc3ab
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
golang.org/x/sys v0.0.0-20210301091718-77cc2087c03b h1:kHlr0tATeLRMEiZJu5CknOw/E8V6h69sXXQFGoPtjcc=
|
golang.org/x/sys v0.29.1-0.20250107080300-1c14dcadc3ab h1:BMkEEWYOjkvOX7+YKOGbp6jCyQ5pR2j0Ah47p1Vdsx4=
|
||||||
golang.org/x/sys v0.0.0-20210301091718-77cc2087c03b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.29.1-0.20250107080300-1c14dcadc3ab/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// Copyright (c) 2021 AUTHORS All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package peercred
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
osGet = getSolaris
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSolaris(c net.Conn) (*Creds, error) {
|
||||||
|
switch c := c.(type) {
|
||||||
|
case *net.UnixConn:
|
||||||
|
return getUnix(c)
|
||||||
|
case *net.TCPConn:
|
||||||
|
// TODO: Need ideas
|
||||||
|
}
|
||||||
|
return nil, ErrUnsupportedConnType
|
||||||
|
}
|
||||||
|
|
||||||
|
func getUnix(c *net.UnixConn) (*Creds, error) {
|
||||||
|
raw, err := c.SyscallConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("SyscallConn: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var creds *unix.Ucred
|
||||||
|
cerr := raw.Control(func(fd uintptr) {
|
||||||
|
creds, err = unix.GetPeerUcred(fd)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("unix.GetPeerUcred: %w", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if cerr != nil {
|
||||||
|
return nil, fmt.Errorf("raw.Control: %w", cerr)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Creds{
|
||||||
|
pid: creds.Getpid(),
|
||||||
|
uid: strconv.FormatUint(uint64(creds.Geteuid()), 10),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
//go:build go1.15 && (linux || darwin || freebsd)
|
//go:build go1.15 && (linux || darwin || freebsd || illumos || solaris)
|
||||||
|
|
||||||
package peercred
|
package peercred
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user