Skip to content

Commit

Permalink
Merge pull request #44 from mischief/dotu-uid-fallback
Browse files Browse the repository at this point in the history
p/srv: properly fallback to uname with ~0 uid in dotu
  • Loading branch information
lionkov committed Feb 5, 2016
2 parents 865dee6 + cfffd12 commit 851876e
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions p/srv/fcall.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@ func (srv *Srv) version(req *Req) {
req.RespondRversion(conn.Msize, ver)
}

func (srv *Srv) getUser(req *Req) p.User {
tc := req.Tc
conn := req.Conn

var user p.User = nil

if conn.Dotu {
// from the 9p2000.u specification:
// A numeric uname field has been added to the attach and auth
// messages in order to provide hints to map a string to a
// numeric id if such a facility is not available. The numeric
// uname should be given preference over the uname string
// unless n_uname is unspecified (~0).
if tc.Unamenum != p.NOUID {
user = srv.Upool.Uid2User(int(tc.Unamenum))
} else if tc.Uname != "" {
user = srv.Upool.Uname2User(tc.Uname)
}
} else if tc.Uname != "" {
user = srv.Upool.Uname2User(tc.Uname)
}

return user
}

func (srv *Srv) auth(req *Req) {
tc := req.Tc
conn := req.Conn
Expand All @@ -59,13 +84,7 @@ func (srv *Srv) auth(req *Req) {
return
}

var user p.User = nil
if tc.Unamenum != p.NOUID || conn.Dotu {
user = srv.Upool.Uid2User(int(tc.Unamenum))
} else if tc.Uname != "" {
user = srv.Upool.Uname2User(tc.Uname)
}

user := srv.getUser(req)
if user == nil {
req.RespondError(Enouser)
return
Expand Down Expand Up @@ -114,13 +133,7 @@ func (srv *Srv) attach(req *Req) {
}
}

var user p.User = nil
if tc.Unamenum != p.NOUID || conn.Dotu {
user = srv.Upool.Uid2User(int(tc.Unamenum))
} else if tc.Uname != "" {
user = srv.Upool.Uname2User(tc.Uname)
}

user := srv.getUser(req)
if user == nil {
req.RespondError(Enouser)
return
Expand Down

0 comments on commit 851876e

Please sign in to comment.