diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-10-05 13:40:27 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-10-05 13:40:27 +0000 |
commit | 27d4af103f9d17e1dd4985f48ff5cc36cffaad60 (patch) | |
tree | 4dd983ca664da18f44e8f2d70d75e9e051b94254 | |
parent | 53196350c9190f84380a801b017f0f700bba7b73 (diff) | |
download | fetchmail-27d4af103f9d17e1dd4985f48ff5cc36cffaad60.tar.gz fetchmail-27d4af103f9d17e1dd4985f48ff5cc36cffaad60.tar.bz2 fetchmail-27d4af103f9d17e1dd4985f48ff5cc36cffaad60.zip |
Eliminate set_defaults so user variable will be available in main.
svn path=/trunk/; revision=224
-rw-r--r-- | fetchmail.c | 44 | ||||
-rw-r--r-- | fetchmail.h | 1 | ||||
-rw-r--r-- | options.c | 59 |
3 files changed, 36 insertions, 68 deletions
diff --git a/fetchmail.c b/fetchmail.c index ecf398e4..861544f6 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -83,12 +83,43 @@ char **argv; int mboxfd, st, sargc; struct hostrec cmd_opts, def_opts; int parsestatus, implicitmode; - char *servername, *user, *tmpdir, tmpbuf[BUFSIZ], *sargv[64]; + char *servername, *user, *home, *tmpdir, tmpbuf[BUFSIZ], *sargv[64]; FILE *tmpfp; pid_t pid; - if (setdefaults(&def_opts) != 0) - exit(PS_UNDEFINED); + memset(&def_opts, '\0', sizeof(struct hostrec)); + + if ((user = getenv("USER")) == (char *)NULL) + user = getenv("LOGNAME"); + + if ((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"); + exit(PS_UNDEFINED); + } + } + + def_opts.protocol = P_AUTO; + + strcpy(def_opts.remotename, user); + strcpy(def_opts.smtphost, "localhost"); + + rcfile = + (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2); + strcpy(rcfile, home); + strcat(rcfile, "/"); + strcat(rcfile, RCFILE_NAME); + + outlevel = O_NORMAL; if (argc > sizeof(sargv)) exit(PS_SYNTAX); @@ -153,11 +184,8 @@ char **argv; strcpy(tmpbuf, tmpdir); strcat(tmpbuf, "/fetchmail-"); gethostname(tmpbuf + strlen(tmpbuf), HOSTLEN+1); - if ((user = getenv("USER")) != (char *)NULL) - { - strcat(tmpbuf, "-"); - strcat(tmpbuf, user); - } + strcat(tmpbuf, "-"); + strcat(tmpbuf, user); /* perhaps we just want to check options? */ if (versioninfo) { diff --git a/fetchmail.h b/fetchmail.h index ef49b23d..9c7f0e9f 100644 --- a/fetchmail.h +++ b/fetchmail.h @@ -124,7 +124,6 @@ int doPOP3 (struct hostrec *); int doIMAP (struct hostrec *); int parsecmdline (int, char **, struct hostrec *); -int setdefaults (struct hostrec *); char *getnextserver (int argc, char **, int *); char *MD5Digest (char *); int openmailpipe (struct hostrec *); @@ -238,65 +238,6 @@ struct hostrec *queryctl; return(optind); } - - -/********************************************************************* - function: setdefaults - description: set reasonable default values for unspecified options. - arguments: - options option values parsed from the command-line; unspeci- - fied options must be filled with zero. - - return value: zero if defaults were successfully set, else non-zero - (indicates a problem reading /etc/passwd). - calls: none. - globals: writes outlevel, rcfile. - *********************************************************************/ -#include <stdlib.h> - -int setdefaults (queryctl) -struct hostrec *queryctl; -{ - char *user, *home; - - memset(queryctl, '\0', 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 = P_AUTO; - queryctl->keep = 0; - queryctl->norewrite = 0; - - strcpy(queryctl->remotename, user); - strcpy(queryctl->smtphost, "localhost"); - - rcfile = - (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2); - strcpy(rcfile, home); - strcat(rcfile, "/"); - strcat(rcfile, RCFILE_NAME); - - outlevel = O_NORMAL; - - return(0); -} - - /****************************************************************** function: getnextserver |