aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-09-20 14:59:21 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-09-20 14:59:21 +0000
commit49e46d92e5a5c7adeb5aebdf923aa78639b4ca61 (patch)
tree5dddf9c77b42728dff25dff5b17574deaca04581
parentb2ad72a23f867bcdc9a18802dc7989a8a9ae7ad1 (diff)
downloadfetchmail-49e46d92e5a5c7adeb5aebdf923aa78639b4ca61.tar.gz
fetchmail-49e46d92e5a5c7adeb5aebdf923aa78639b4ca61.tar.bz2
fetchmail-49e46d92e5a5c7adeb5aebdf923aa78639b4ca61.zip
Be robust in the presence of Sun NIS and other nonstandard password schemes.
svn path=/trunk/; revision=101
-rw-r--r--NEWS3
-rw-r--r--fetchmail.man6
-rw-r--r--options.c77
3 files changed, 53 insertions, 33 deletions
diff --git a/NEWS b/NEWS
index 7a815aef..f6db5654 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/options.c b/options.c
index 8a86dc16..188464b0 100644
--- a/options.c
+++ b/options.c
@@ -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);
}