Skip to content

p/srv: properly fallback to uname with ~0 uid in dotu #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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