From b7de8535f899f2b88d61f4f1264fe6a272196536 Mon Sep 17 00:00:00 2001 From: Joseph Richey Date: Thu, 19 Oct 2017 03:15:28 -0700 Subject: util: Add better user lookup functions When looking up users in fscrypt, we often want to proceed even if the requested uid doesn't appear to be a valid user on the system. This mainly occurs when a user is deleted, but they still have a login protector on disk. Thus, GetUser() with a bad uid creates a fake user with a pretty placeholder name. The corresponding call sites of util.EffectiveUser are changed (often simplifying logic). Various documentation is updated and typos are fixed. --- actions/context.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'actions/context.go') diff --git a/actions/context.go b/actions/context.go index 8ad1357..ed7729d 100644 --- a/actions/context.go +++ b/actions/context.go @@ -67,7 +67,7 @@ type Context struct { // NewContextFromPath makes a context for the filesystem containing the // specified path and whose Config is loaded from the global config file. On // success, the Context contains a valid Config and Mount. The target defaults -// the the current effective user if none is specified. +// the the current user if none is specified. func NewContextFromPath(path string, target *user.User) (*Context, error) { ctx, err := newContextFromUser(target) if err != nil { @@ -85,7 +85,7 @@ func NewContextFromPath(path string, target *user.User) (*Context, error) { // NewContextFromMountpoint makes a context for the filesystem at the specified // mountpoint and whose Config is loaded from the global config file. On // success, the Context contains a valid Config and Mount. The target defaults -// the the current effective user if none is specified. +// the the current user if none is specified. func NewContextFromMountpoint(mountpoint string, target *user.User) (*Context, error) { ctx, err := newContextFromUser(target) if err != nil { @@ -102,13 +102,11 @@ func NewContextFromMountpoint(mountpoint string, target *user.User) (*Context, e // newContextFromUser makes a context with the corresponding target user, and // whose Config is loaded from the global config file. If the target is nil, the -// effecitive user is used. +// current user is used. func newContextFromUser(target *user.User) (*Context, error) { var err error if target == nil { - if target, err = util.EffectiveUser(); err != nil { - return nil, err - } + target = util.CurrentUser() } ctx := &Context{TargetUser: target} -- cgit v1.3