本文整理汇总了Golang中github.com/lionkov/go9p/p.User类的典型用法代码示例。如果您正苦于以下问题:Golang User类的具体用法?Golang User怎么用?Golang User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Attach
// 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
clnt.Root = fid
return fid, nil
}
示例2: Auth
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)
}
示例3: Auth
// 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
}
示例4: Attach
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)
}
示例5: CheckPerm
// Checks if the specified user has permission to perform
// certain operation on a file. Perm contains one or more
// of DMREAD, DMWRITE, and DMEXEC.
func CheckPerm(f *p.Dir, 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
}
示例6: Add
// 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
}