// Creates a fid for the specified user that points to the root // of the file server's file tree. Returns a Fid pointing to the root, // if successful, or an Error. func (clnt *Clnt) Attach(afid *Fid, user p.User, aname string) (*Fid, error) { var afno uint32 if afid != nil { afno = afid.Fid } else { afno = p.NOFID } fid := clnt.FidAlloc() tc := clnt.NewFcall() err := p.PackTattach(tc, fid.Fid, afno, user.Name(), aname, uint32(user.Id()), clnt.Dotu) if err != nil { return nil, err } rc, err := clnt.Rpc(tc) if err != nil { return nil, err } fid.Qid = rc.Qid fid.User = user fid.walked = true return fid, nil }
func (tag *Tag) Auth(afid *Fid, user p.User, aname string) error { req := tag.reqAlloc() req.fid = afid err := p.PackTauth(req.Tc, afid.Fid, user.Name(), aname, uint32(user.Id()), tag.clnt.Dotu) if err != nil { return err } afid.User = user return tag.clnt.Rpcnb(req) }
// Creates an authentication fid for the specified user. Returns the fid, if // successful, or an Error. func (clnt *Clnt) Auth(user p.User, aname string) (*Fid, error) { fid := clnt.FidAlloc() tc := clnt.NewFcall() err := p.PackTauth(tc, fid.Fid, user.Name(), aname, uint32(user.Id()), clnt.Dotu) if err != nil { return nil, err } _, err = clnt.Rpc(tc) if err != nil { return nil, err } fid.Iounit = clnt.Msize - p.IOHDRSZ fid.User = user fid.walked = true return fid, nil }
func (tag *Tag) Attach(fid, afid *Fid, user p.User, aname string) error { var afno uint32 if afid != nil { afno = afid.Fid } else { afno = p.NOFID } req := tag.reqAlloc() req.fid = fid err := p.PackTattach(req.Tc, fid.Fid, afno, user.Name(), aname, uint32(user.Id()), tag.clnt.Dotu) if err != nil { return err } fid.User = user return tag.clnt.Rpcnb(req) }
// Checks if the specified user has permission to perform // certain operation on a file. Perm contains one or more // of p.DMREAD, p.DMWRITE, and p.DMEXEC. func (f *File) CheckPerm(user p.User, perm uint32) bool { if user == nil { return false } perm &= 7 /* other permissions */ fperm := f.Mode & 7 if (fperm & perm) == perm { return true } /* user permissions */ if f.Uid == user.Name() || f.Uidnum == uint32(user.Id()) { fperm |= (f.Mode >> 6) & 7 } if (fperm & perm) == perm { return true } /* group permissions */ groups := user.Groups() if groups != nil && len(groups) > 0 { for i := 0; i < len(groups); i++ { if f.Gid == groups[i].Name() || f.Gidnum == uint32(groups[i].Id()) { fperm |= (f.Mode >> 3) & 7 break } } } if (fperm & perm) == perm { return true } return false }
// Initializes the fields of a file and add it to a directory. // Returns nil if successful, or an error. func (f *File) Add(dir *File, name string, uid p.User, gid p.Group, mode uint32, ops interface{}) error { lock.Lock() qpath := qnext qnext++ lock.Unlock() f.Qid.Type = uint8(mode >> 24) f.Qid.Version = 0 f.Qid.Path = qpath f.Mode = mode f.Atime = uint32(time.Now().Unix()) f.Mtime = f.Atime f.Length = 0 f.Name = name if uid != nil { f.Uid = uid.Name() f.Uidnum = uint32(uid.Id()) } else { f.Uid = "none" f.Uidnum = p.NOUID } if gid != nil { f.Gid = gid.Name() f.Gidnum = uint32(gid.Id()) } else { f.Gid = "none" f.Gidnum = p.NOUID } f.Muid = "" f.Muidnum = p.NOUID f.Ext = "" if dir != nil { f.Parent = dir dir.Lock() for p := dir.cfirst; p != nil; p = p.next { if name == p.Name { dir.Unlock() return Eexist } } if dir.clast != nil { dir.clast.next = f } else { dir.cfirst = f } f.prev = dir.clast f.next = nil dir.clast = f dir.Unlock() } else { f.Parent = f } f.Ops = ops return nil }