Remove redundant methods

This commit is contained in:
2025-04-05 15:17:24 -04:00
parent dcf2844318
commit d116525c2b
8 changed files with 16 additions and 29 deletions
+2 -13
View File
@@ -8,17 +8,6 @@ package peercred
// Creds are the peer credentials. // Creds are the peer credentials.
type Creds struct { type Creds struct {
pid int PID int
uid string 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
} }
+2 -2
View File
@@ -42,7 +42,7 @@ func get(c *net.UnixConn) (*Creds, error) {
return nil, err return nil, err
} }
return &Creds{ return &Creds{
pid: pid, PID: pid,
uid: strconv.FormatUint(uint64(cred.Uid), 10), UID: strconv.FormatUint(uint64(cred.Uid), 10),
}, nil }, nil
} }
+2 -2
View File
@@ -35,7 +35,7 @@ func get(c *net.UnixConn) (*Creds, error) {
return nil, err return nil, err
} }
return &Creds{ return &Creds{
pid: int(cred.Pid), PID: int(cred.Pid),
uid: strconv.FormatUint(uint64(cred.Uid), 10), UID: strconv.FormatUint(uint64(cred.Uid), 10),
}, nil }, nil
} }
+2 -2
View File
@@ -31,7 +31,7 @@ func get(c *net.UnixConn) (*Creds, error) {
return nil, fmt.Errorf("unix.GetsockoptUcred: %w", err) return nil, fmt.Errorf("unix.GetsockoptUcred: %w", err)
} }
return &Creds{ return &Creds{
pid: int(cred.Pid), PID: int(cred.Pid),
uid: strconv.FormatUint(uint64(cred.Uid), 10), UID: strconv.FormatUint(uint64(cred.Uid), 10),
}, nil }, nil
} }
+2 -2
View File
@@ -33,7 +33,7 @@ func get(c *net.UnixConn) (*Creds, error) {
return nil, err return nil, err
} }
return &Creds{ return &Creds{
pid: creds.Getpid(), PID: creds.Getpid(),
uid: strconv.FormatUint(uint64(creds.Geteuid()), 10), UID: strconv.FormatUint(uint64(creds.Geteuid()), 10),
}, nil }, nil
} }
-2
View File
@@ -4,8 +4,6 @@
// 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.
// Package peercred maps from a net.Conn to information about the
// other side of the connection, using various OS-specific facilities.
package peercred package peercred
import "net" import "net"
+2 -2
View File
@@ -50,7 +50,7 @@ func TestUnixSock(t *testing.T) {
t.Fatalf("Get: %v", err) t.Fatalf("Get: %v", err)
} }
uid := creds.UID() uid := creds.UID
if uid == "" { if uid == "" {
t.Errorf("no UID") t.Errorf("no UID")
} }
@@ -58,7 +58,7 @@ func TestUnixSock(t *testing.T) {
t.Errorf("UID = %q; want %q", got, want) t.Errorf("UID = %q; want %q", got, want)
} }
pid := creds.PID() pid := creds.PID
if pid == 0 { if pid == 0 {
t.Errorf("no PID") t.Errorf("no PID")
} }
+4 -4
View File
@@ -11,8 +11,8 @@ import (
) )
// Get returns the peer credentials for c. // Get returns the peer credentials for c.
func Get(h *windows.Handle) *Creds { func Get(h windows.Handle) *Creds {
creds, _ := get(h) creds, _ := get(&h)
return creds return creds
} }
@@ -37,7 +37,7 @@ func get(h *windows.Handle) (*Creds, error) {
} }
return &Creds{ return &Creds{
pid: int(clientPID), PID: int(clientPID),
uid: tokenUser.User.Sid.String(), UID: tokenUser.User.Sid.String(),
}, nil }, nil
} }