mirror of
https://github.com/rwinkhart/peercred-mini.git
synced 2026-08-27 20:36:30 -04:00
Remove redundant methods
This commit is contained in:
+2
-13
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user