{
struct passwd by_name, by_uid, *pwp;
- if (!(user = getenv("LOGNAME")))
- user = getenv("USER");
+ (user = getenv("FETCHMAILUSER"))
+ || (user = getenv("LOGNAME"))
+ || (user = getenv("USER"));
if (!(pwp = getpwuid(getuid())))
{
else
{
memcpy(&by_uid, pwp, sizeof(struct passwd));
- if (!user)
+ if (!user || !(pwp = getpwnam(user)))
pwp = &by_uid;
- else if ((pwp = getpwnam(user)))
+ else
{
/*
* This logic is needed to handle gracefully the possibility
- * that multiple names might be mapped to one UID
+ * that multiple names might be mapped to one UID.
*/
memcpy(&by_name, pwp, sizeof(struct passwd));
else
pwp = &by_uid;
}
- else
- {
- fprintf(stderr,
- _("%s: can't find your name and home directory!\n"),
- program_name);
- exit(PS_UNDEFINED);
- }
user = xstrdup(pwp->pw_name);
}
lock file to help prevent concurrent runs (root mode, systems without /var/run).
.SH ENVIRONMENT
-If either the LOGNAME or USER variable is correctly set
-(e.g. the corresponding UID matches the session user ID) then that
-name is used as the default local name. Otherwise \fBgetpwuid\fR(3)
-must be able to retrieve a password entry for the session ID (this
-elaborate logic is designed to handle the case of multiple names per
-userid gracefully).
+If the FETCHMAILUSER variable is set, it is used as the name of the
+calling user (default local name) for purposes such as mailing error
+notifications. Otherwise, if either the LOGNAME or USER variable is
+correctly set (e.g. the corresponding UID matches the session user ID)
+then that name is used as the default local name. Otherwise
+\fBgetpwuid\fR(3) must be able to retrieve a password entry for the
+session ID (this elaborate logic is designed to handle the case of
+multiple names per userid gracefully).
If the environment variable FETCHMAILHOME is set to a valid and
existing directory name, the .fetchmailrc and .fetchids and