If parse_plist_config() is called with a non-absolute path which
is defined as a path whose first character is not '/', then
CFReadStreamCreateWithFile() must determine the current working
directory in order to return a CFURLRef to an absolute path.
If getcwd() fails, then CFReadStreamCreateWithFile() returns
NULL.
Instead of unconditionally returning ENOMEM when NULL is returned,
check if the path is non-absolute and call getcwd(). If getcwd()
fails, return errno. Otherwise, return ENOMEM. This permits
ENOENT (a component of the pathname no longer exists) or EACCES
(read or search permission was denied for a component of the
pathname) to be returned as the reason.
ENOMEM is a fatal error when constructing the configuration for
krb5_init_context() whereas ENOENT and EACCES are not fatal.
Without this patch on macOS, if the cwd is in /afs and the user's
tokens have expired, then krb5_init_context() fails with ENOMEM (12).
user@MacBookAir user % ~/src/heimdal/kuser/heimtools klist
shell-init: error retrieving current directory: \
getcwd: cannot access parent directories: Permission denied
chdir: error retrieving current directory: \
getcwd: cannot access parent directories: Permission denied
heimtools: krb5_init_context failed: 12
With this change krb5_init_context() succeeds.