// Access implements fs.NodeAccesser interface for *Root.
166420
func (*Root) Access(ctx context.Context, r *fuse.AccessRequest) error {
	if int(r.Uid) != os.Getuid() &&
		// Finder likes to use UID 0 for some operations. osxfuse already allows
		// ACCESS and GETXATTR requests from root to go through. This allows root
		// in ACCESS handler. See KBFS-1733 for more details.
		int(r.Uid) != 0 {
		// short path: not accessible by anybody other than root or the user who
		// executed the kbfsfuse process.
		return fuse.EPERM
	}

	if r.Mask&02 != 0 {
		return fuse.EPERM
	}

	return nil
}
737221
func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			start := time.Now()
			lw := mutil.WrapWriter(w)
			next.ServeHTTP(lw, r)
			f(r, lw.Status(), lw.BytesWritten(), time.Since(start))
		})
	}
}
659378
func GrantAccess(rNames, uNames []string, readOnly bool) error {
	conn, err := db.Conn()
	if err != nil {
		return err
	}
	defer conn.Close()
	var info *mgo.ChangeInfo
	if readOnly {
		info, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"readonlyusers": bson.M{"$each": uNames}}})
	} else {
		info, err = conn.Repository().UpdateAll(bson.M{"_id": bson.M{"$in": rNames}}, bson.M{"$addToSet": bson.M{"users": bson.M{"$each": uNames}}})
	}
	if err != nil {
		return err
	}
	if info.Matched == 0 {
		return ErrRepositoryNotFound
	}
	return nil
}
397405
func RootCause(err error) error {
	if ex, ok := err.(Err); ok {
		return RootCause(ex.Err())
	}
	return err
}
61756
func (k *Item) SetAccess(a *Access) {
	if a != nil {
		k.attr[AccessKey] = a
	} else {
		delete(k.attr, AccessKey)
	}
}
210799
func (r Root) Find(args ...string) Root {
	temp, ok := findOnce(r.Pointer, args, false, false)
	if ok == false {
		if debug {
			panic("Element `" + args[0] + "` with attributes `" + strings.Join(args[1:], " ") + "` not found")
		}
		return Root{nil, "", errors.New("element `" + args[0] + "` with attributes `" + strings.Join(args[1:], " ") + "` not found")}
	}
	return Root{temp, temp.Data, nil}
}
247629
func (r *RootCMD) Run() {
	if len(os.Args) < 2 {
		r.Usage()
		os.Exit(1)
	}
	p, sub := options.NewParser(os.Args[1:])
	if sub == "" {
		r.Usage()
		os.Exit(1)
	}
	// Get the subcommand if it exists
	c := r.Subcommands[sub]
	if c == nil {
		// Try to get the subcommand by alias if it not found as a normal name
		if alias := r.Aliases[sub]; alias != "" {
			c = r.Subcommands[alias]
		}
		if c == nil {
			r.Usage()
			os.Exit(1)
		}
	}
	// Handle any flags for the RootCMD
	if r.Flags != nil {
		p.SetFlags(r.Flags)
	}
	// Not yet supported
	//p.SubFlags(c)
	// Handle the arguments for the subcommand
	if !p.SetArgs(c.Args) {
		Usage(r, c)
		os.Exit(1)
	}
	c.Run(r, c)
}
579110
func (e *EnsureQuestAttempts) Root(c context.Context) *datastore.Key {
	return model.QuestKeyFromID(c, e.Quest.ID)
}
664485
func (s *sccAcct) visit(n Node) int {
	idx := s.NextIndex
	s.NodeIndex[n] = idx
	s.NextIndex++
	s.push(n)
	return idx
}
422410
func (r *Root) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (_ fs.Node, err error) {
	r.log().CDebugf(ctx, "FS Lookup %s", req.Name)
	defer func() { err = r.private.fs.processError(ctx, libkbfs.ReadMode, err) }()

	specialNode := handleNonTLFSpecialFile(
		req.Name, r.private.fs, &resp.EntryValid)
	if specialNode != nil {
		return specialNode, nil
	}

	platformNode, err := r.platformLookup(ctx, req, resp)
	if platformNode != nil || err != nil {
		return platformNode, err
	}

	switch req.Name {
	case PrivateName:
		return r.private, nil
	case PublicName:
		return r.public, nil
	}

	if req.Name == TeamName {
		return r.team, nil
	}

	// Don't want to pop up errors on special OS files.
	if strings.HasPrefix(req.Name, ".") {
		return nil, fuse.ENOENT
	}

	return nil, libkbfs.NoSuchFolderListError{
		Name:     req.Name,
		PrivName: PrivateName,
		PubName:  PublicName,
	}
}
568452
func (e ReadAccessError) Error() string {
	return fmt.Sprintf("%s does not have read access to directory %s",
		e.User, BuildCanonicalPathForTlfName(e.Type, e.Tlf))
}
988869
func (c *Context) Root() *Context {
	if c.Parent != nil {
		return c.Parent.Root()
	}
	return c
}
922649
func (h *accessAuthenticator) HandleAccess(ar *osin.AccessRequest, w http.ResponseWriter) error {
	var (
		info *authenticator.Response
		ok   bool
		err  error
	)

	switch ar.Type {
	case osin.AUTHORIZATION_CODE, osin.REFRESH_TOKEN:
		// auth codes and refresh tokens are assumed allowed
		ok = true
	case osin.PASSWORD:
		ctx := context.TODO()
		if ar.HttpRequest != nil {
			ctx = ar.HttpRequest.Context()
		}
		info, ok, err = h.password.AuthenticatePassword(ctx, ar.Username, ar.Password)
	case osin.ASSERTION:
		info, ok, err = h.assertion.AuthenticateAssertion(ar.AssertionType, ar.Assertion)
	case osin.CLIENT_CREDENTIALS:
		info, ok, err = h.client.AuthenticateClient(ar.Client)
	default:
		klog.Warningf("Received unknown access token type: %s", ar.Type)
	}

	if err != nil {
		klog.V(4).Infof("Unable to authenticate %s: %v", ar.Type, err)
		return err
	}

	if ok {
		// Disable refresh_token generation
		ar.GenerateRefresh = false
		ar.Authorized = true
		if info != nil {
			// TODO something with audiences?
			ar.AccessData.UserData = info.User
		}

		if e, ok := ar.Client.(TokenMaxAgeSeconds); ok {
			if maxAge := e.GetTokenMaxAgeSeconds(); maxAge != nil {
				ar.Expiration = *maxAge
			}
		}
	}

	return nil
}
394904
func (c *Client) GrantAccess(rNames, uNames []string) error {
	b := map[string][]string{"repositories": rNames, "users": uNames}
	return c.post(b, "/repository/grant")
}
472087
func (ti *TemplateInstance) Root() Node {
	node, _ := NodeTree(ti.Definition.Data.Elements, 0)
	return node
}
729816
func (ncs *nodeCacheStandard) Get(ref data.BlockRef) (n Node) {
	if ref == (data.BlockRef{}) {
		return nil
	}

	// Temporary code to track down bad block pointers. Remove (or
	// return an error) when not needed anymore.
	if !ref.IsValid() {
		panic(InvalidBlockRefError{ref})
	}

	var rootWrappers []func(Node) Node
	var parent Node
	defer func() {
		if n != nil {
			n = ncs.wrapNodeStandard(n, rootWrappers, parent)
		}
	}()

	ncs.lock.Lock()
	defer ncs.lock.Unlock()
	rootWrappers = ncs.rootWrappers
	entry, ok := ncs.nodes[ref]
	if !ok {
		return nil
	}
	ns := ncs.makeNodeStandardForEntryLocked(entry)
	parent = ns.core.parent // get while under lock
	return ns
}
405353
func (f *NotifyExecution) Root(c context.Context) *ds.Key {
	return model.ExecutionKeyFromID(c, f.Notification.ID)
}