示例#1
0
文件: tag.go 项目: jsouthworth/ixp
func (tag *Tag) Auth(afid *Fid, user ixp.User, aname string) error {
	req := tag.reqAlloc()
	req.fid = afid
	err := ixp.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)
}
示例#2
0
文件: tag.go 项目: jsouthworth/ixp
func (tag *Tag) Attach(fid, afid *Fid, user ixp.User, aname string) error {
	var afno uint32

	if afid != nil {
		afno = afid.Fid
	} else {
		afno = ixp.NOFID
	}

	req := tag.reqAlloc()
	req.fid = fid
	err := ixp.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)
}
示例#3
0
文件: file.go 项目: jsouthworth/ixp
// Checks if the specified user has permission to perform
// certain operation on a file. Perm contains one or more
// of ixp.DMREAD, ixp.DMWRITE, and ixp.DMEXEC.
func (f *File) CheckPerm(user ixp.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
}
示例#4
0
文件: file.go 项目: jsouthworth/ixp
// Initializes the fields of a file and add it to a directory.
// Returns nil if successful, or an error.
func (dir *File) Add(f *File, name string, uid ixp.User, gid ixp.Group, mode uint32, ops interface{}) error {
	if dir == nil {
		return Enoent
	}

	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 = ixp.NOUID
	}

	if gid != nil {
		f.Gid = gid.Name()
		f.Gidnum = uint32(gid.Id())
	} else {
		f.Gid = "none"
		f.Gidnum = ixp.NOUID
	}

	f.Muid = ""
	f.Muidnum = ixp.NOUID
	f.Ext = ""

	if dir != f {
		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
}