From cfffd129e3c44353ac645dc4fb2bd227fceeeac3 Mon Sep 17 00:00:00 2001 From: Nick Owens Date: Fri, 5 Feb 2016 14:29:16 -0800 Subject: [PATCH] p/srv: properly fallback to uname with ~0 uid in dotu --- p/srv/fcall.go | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/p/srv/fcall.go b/p/srv/fcall.go index 55779bb..21892dd 100644 --- a/p/srv/fcall.go +++ b/p/srv/fcall.go @@ -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 @@ -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 @@ -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