From d116525c2b4182a5c19f9a641883180140f0b951 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 5 Apr 2025 15:17:24 -0400 Subject: [PATCH] Remove redundant methods --- peercred.go | 15 ++------------- peercred_darwin.go | 4 ++-- peercred_freebsd.go | 4 ++-- peercred_linux.go | 4 ++-- peercred_solaris.go | 4 ++-- peercred_unix_generic.go | 2 -- peercred_unix_test.go | 4 ++-- peercred_windows.go | 8 ++++---- 8 files changed, 16 insertions(+), 29 deletions(-) diff --git a/peercred.go b/peercred.go index 72b2c9a..e049d0e 100644 --- a/peercred.go +++ b/peercred.go @@ -8,17 +8,6 @@ package peercred // Creds are the peer credentials. type Creds struct { - pid int - uid string -} - -// PID returns the process ID associated with the other side of the connection. -func (c *Creds) PID() (pid int) { - return c.pid -} - -// UID returns the userid (or Windows SID) that owns the other side of the connection. -// The returned string is suitable to passing to os/user.LookupId. -func (c *Creds) UID() (uid string) { - return c.uid + PID int + UID string } diff --git a/peercred_darwin.go b/peercred_darwin.go index de4152d..94d23a8 100644 --- a/peercred_darwin.go +++ b/peercred_darwin.go @@ -42,7 +42,7 @@ func get(c *net.UnixConn) (*Creds, error) { return nil, err } return &Creds{ - pid: pid, - uid: strconv.FormatUint(uint64(cred.Uid), 10), + PID: pid, + UID: strconv.FormatUint(uint64(cred.Uid), 10), }, nil } diff --git a/peercred_freebsd.go b/peercred_freebsd.go index 6262e11..5aa8c11 100644 --- a/peercred_freebsd.go +++ b/peercred_freebsd.go @@ -35,7 +35,7 @@ func get(c *net.UnixConn) (*Creds, error) { return nil, err } return &Creds{ - pid: int(cred.Pid), - uid: strconv.FormatUint(uint64(cred.Uid), 10), + PID: int(cred.Pid), + UID: strconv.FormatUint(uint64(cred.Uid), 10), }, nil } diff --git a/peercred_linux.go b/peercred_linux.go index 1261fe6..819817e 100644 --- a/peercred_linux.go +++ b/peercred_linux.go @@ -31,7 +31,7 @@ func get(c *net.UnixConn) (*Creds, error) { return nil, fmt.Errorf("unix.GetsockoptUcred: %w", err) } return &Creds{ - pid: int(cred.Pid), - uid: strconv.FormatUint(uint64(cred.Uid), 10), + PID: int(cred.Pid), + UID: strconv.FormatUint(uint64(cred.Uid), 10), }, nil } diff --git a/peercred_solaris.go b/peercred_solaris.go index 0e1fdbb..60e6477 100644 --- a/peercred_solaris.go +++ b/peercred_solaris.go @@ -33,7 +33,7 @@ func get(c *net.UnixConn) (*Creds, error) { return nil, err } return &Creds{ - pid: creds.Getpid(), - uid: strconv.FormatUint(uint64(creds.Geteuid()), 10), + PID: creds.Getpid(), + UID: strconv.FormatUint(uint64(creds.Geteuid()), 10), }, nil } diff --git a/peercred_unix_generic.go b/peercred_unix_generic.go index f4b37b0..53f65dc 100644 --- a/peercred_unix_generic.go +++ b/peercred_unix_generic.go @@ -4,8 +4,6 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package peercred maps from a net.Conn to information about the -// other side of the connection, using various OS-specific facilities. package peercred import "net" diff --git a/peercred_unix_test.go b/peercred_unix_test.go index ec39181..2441536 100644 --- a/peercred_unix_test.go +++ b/peercred_unix_test.go @@ -50,7 +50,7 @@ func TestUnixSock(t *testing.T) { t.Fatalf("Get: %v", err) } - uid := creds.UID() + uid := creds.UID if uid == "" { t.Errorf("no UID") } @@ -58,7 +58,7 @@ func TestUnixSock(t *testing.T) { t.Errorf("UID = %q; want %q", got, want) } - pid := creds.PID() + pid := creds.PID if pid == 0 { t.Errorf("no PID") } diff --git a/peercred_windows.go b/peercred_windows.go index fa44cd5..8dfb21d 100644 --- a/peercred_windows.go +++ b/peercred_windows.go @@ -11,8 +11,8 @@ import ( ) // Get returns the peer credentials for c. -func Get(h *windows.Handle) *Creds { - creds, _ := get(h) +func Get(h windows.Handle) *Creds { + creds, _ := get(&h) return creds } @@ -37,7 +37,7 @@ func get(h *windows.Handle) (*Creds, error) { } return &Creds{ - pid: int(clientPID), - uid: tokenUser.User.Sid.String(), + PID: int(clientPID), + UID: tokenUser.User.Sid.String(), }, nil }