Skip to content

Commit

Permalink
Allow Uname mismatch in Tattach
Browse files Browse the repository at this point in the history
Since we don't have any authentication and some libraries get Uname
wrong anyway, allow Uname mismatch.
  • Loading branch information
fhs authored and rjkroege committed Sep 26, 2019
1 parent 5287cc7 commit 4035864
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 9 additions & 2 deletions fsys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
"log"
"os"
"os/user"
"sort"
Expand Down Expand Up @@ -275,7 +276,12 @@ func (fs *fileServer) flush(x *Xfid, f *Fid) *Xfid {

func (fs *fileServer) attach(x *Xfid, f *Fid) *Xfid {
if x.fcall.Uname != fs.username {
return fs.respond(x, nil, ErrPermission)
// Ignore mismatch because some libraries gets it wrong
// anyway. 9fans.net/go/plan9/client just uses the
// $USER environment variable, which is wrong in Windows
// (See `go doc -u -src 9fans.net/go/plan9/client getuser`)
log.Printf("attach from uname %q does not match %q but allowing anyway",
x.fcall.Uname, fs.username)
}
var id uint64
if x.fcall.Aname != "" {
Expand Down Expand Up @@ -640,7 +646,8 @@ func (dt *DirTab) Dir(id int, user string, clock int64) *plan9.Dir {
func getuser() string {
user, err := user.Current()
if err != nil {
return "Wile E. Coyote"
// Same as https://9fans.github.io/usr/local/plan9/src/lib9/getuser.c
return "none"
}
return user.Username
}
12 changes: 10 additions & 2 deletions fsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,18 @@ func TestFileServerAttach(t *testing.T) {
Type: plan9.Tattach,
Uname: "glenda",
},
f: &Fid{},
}
fs.attach(x, nil)
fs.attach(x, x.f)

want := errorFcall(ErrPermission)
want := &plan9.Fcall{
Type: plan9.Rattach,
Qid: plan9.Qid{
Path: Qdir,
Vers: 0,
Type: plan9.QTDIR,
},
}
if got := mc.ReadFcall(t); !cmp.Equal(got, want) {
t.Fatalf("got response %v; want %v", got, want)
}
Expand Down

0 comments on commit 4035864

Please sign in to comment.