diff options
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | fetchmail.man | 6 | ||||
-rw-r--r-- | options.c | 77 |
3 files changed, 53 insertions, 33 deletions
@@ -61,6 +61,9 @@ driver to SMTP. (This requires that we find a POP2 server to test with.) * Warn users that running concurrent instances of popclient is a bad idea. +* Try USER and HOME to set defaults before going to the password file. + This should work in Sun NIS environments. + 3.1: * MDA arguments are now dumped when using the -V option. diff --git a/fetchmail.man b/fetchmail.man index 04a748d1..1e112838 100644 --- a/fetchmail.man +++ b/fetchmail.man @@ -567,6 +567,12 @@ default location of file associating hosts with last message IDs seen .TP 5 ${TMPDIR}/poplock-${HOST}-${USER} lock file to help prevent concurrent runs. +.SH ENVIRONMENT +For correct initialization, +.I popclient +requires either that both the USER and HOME environment variables are +correctly set, or that \fBgetpwuid\fR(3) be able to retrieve a password +entry from your user ID. .SH BUGS Running more than one concurrent instance of .I popclient @@ -224,7 +224,7 @@ struct hostrec *queryctl; break; case 'P': case LA_PORT: - queryctl->port = strtol(optarg,0,0L); + queryctl->port = atoi(optarg); break; case 'S': case LA_SMTPHOST: @@ -307,54 +307,65 @@ struct hostrec *queryctl; calls: none. globals: writes outlevel, poprcfile, idfile. *********************************************************************/ +#include <stdlib.h> int setdefaults (queryctl) struct hostrec *queryctl; { - int uid; - struct passwd *pw; - char *mailvar; - - bzero(queryctl,sizeof(*queryctl)); - - if ((pw = getpwuid(uid = getuid())) == NULL) { - fprintf(stderr,"No passwd entry for uid %d\n",uid); - return(-1); - } + char *user, *home; + + bzero(queryctl,sizeof(*queryctl)); + + if ((user = getenv("USER")) == (char *)NULL + || (home = getenv("HOME")) == (char *)NULL) + { + struct passwd *pw; + + if ((pw = getpwuid(getuid())) != NULL) + { + user = pw->pw_name; + home = pw->pw_dir; + } + else + { + fprintf(stderr,"I can't find your name and home directory!\n"); + return(-1); + } + } - queryctl->protocol = DEF_PROTOCOL; + queryctl->protocol = DEF_PROTOCOL; #if defined(KEEP_IS_DEFAULT) - queryctl->keep = 1; + queryctl->keep = 1; #else - queryctl->keep = 0; + queryctl->keep = 0; #endif - queryctl->norewrite = 0; + queryctl->norewrite = 0; - strcpy(queryctl->localname,pw->pw_name); - strcpy(queryctl->remotename,pw->pw_name); - sprintf(queryctl->userfolder, USERFOLDER, pw->pw_name); - strcpy(queryctl->smtphost, "localhost"); - queryctl->output = TO_SMTP; - (void) sprintf(queryctl->mda, DEF_MDA, queryctl->localname); + strcpy(queryctl->localname, user); + strcpy(queryctl->remotename, user); + sprintf(queryctl->userfolder, USERFOLDER, user); + strcpy(queryctl->smtphost, "localhost"); + queryctl->output = TO_SMTP; + (void) sprintf(queryctl->mda, DEF_MDA, queryctl->localname); - poprcfile = - (char *) xmalloc(strlen(pw->pw_dir)+strlen(POPRC_NAME)+2); + poprcfile = + (char *) xmalloc(strlen(home)+strlen(POPRC_NAME)+2); - strcpy(poprcfile, pw->pw_dir); - strcat(poprcfile, "/"); - strcat(poprcfile, POPRC_NAME); + strcpy(poprcfile, home); + strcat(poprcfile, "/"); + strcat(poprcfile, POPRC_NAME); - idfile = - (char *) xmalloc(strlen(pw->pw_dir)+strlen(IDFILE_NAME)+2); + idfile = + (char *) xmalloc(strlen(home)+strlen(IDFILE_NAME)+2); - strcpy(idfile, pw->pw_dir); - strcat(idfile, "/"); - strcat(idfile, IDFILE_NAME); + strcpy(idfile, home); + strcat(idfile, "/"); + strcat(idfile, IDFILE_NAME); - outlevel = O_NORMAL; + outlevel = O_NORMAL; - return(0); + return(0); } |