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.
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
}
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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
}
+2 -2
View File
@@ -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
}
-2
View File
@@ -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"
+2 -2
View File
@@ -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")
}
+4 -4
View File
@@ -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
}