Skip to content

Commit

Permalink
auth: Send uid rather than username when authenticating
Browse files Browse the repository at this point in the history
There is no particular advantage to sending the username. It just
means the other end has to map it to a uid when comparing with the
uid from getpeercred. Additionally that mapping is not always
possible, as the remote side may not have the correct /etc/passwd.
For instance, this can happen when talking to a dbus service inside
a container.
  • Loading branch information
alexlarsson committed Mar 27, 2014
1 parent 473c940 commit 164977e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"bytes"
"errors"
"io"
"os"
"os/user"
"strconv"
)

// AuthStatus represents the Status of an authentication mechanism.
Expand Down Expand Up @@ -52,11 +54,12 @@ type Auth interface {
// bus. Auth must not be called on shared connections.
func (conn *Conn) Auth(methods []Auth) error {
if methods == nil {
uid := strconv.Itoa(os.Getuid())
u, err := user.Current()
if err != nil {
return err
}
methods = []Auth{AuthExternal(u.Username), AuthCookieSha1(u.Username, u.HomeDir)}
methods = []Auth{AuthExternal(uid), AuthCookieSha1(uid, u.HomeDir)}
}
in := bufio.NewReader(conn.transport)
err := conn.transport.SendNullByte()
Expand Down

0 comments on commit 164977e

Please sign in to comment.