X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=env.c;h=edf998983a88be540d639946ed9c8b669711f07f;hb=49268a95ee78bc179fd3439b3f06e9a06c993c92;hp=cccc4f115dbcdffc2e84bfad1384f4ec0d4a9d63;hpb=4680b0f8c728a69a24e7089b777f03899bab6c9f;p=~andy%2Ffetchmail diff --git a/env.c b/env.c index cccc4f11..edf99898 100644 --- a/env.c +++ b/env.c @@ -30,13 +30,18 @@ #include #endif +#ifndef HAVE_DECL_GETENV extern char *getenv(const char *); /* needed on sysV68 R3V7.1. */ +#endif void envquery(int argc, char **argv) /* set up basic stuff from the environment (including the rc file name) */ { struct passwd by_name, by_uid, *pwp; + (void)argc; + + (void)argc; if (!(user = getenv("FETCHMAILUSER"))) { if (!(user = getenv("LOGNAME"))) @@ -102,10 +107,12 @@ void envquery(int argc, char **argv) user = xstrdup(pwp->pw_name); } + endpwent(); + /* compute user's home directory */ home = getenv("HOME_ETC"); if (!home && !(home = getenv("HOME"))) - home = pwp->pw_dir; + home = xstrdup(pwp->pw_dir); /* compute fetchmail's home directory */ if (!(fmhome = getenv("FETCHMAILHOME"))) @@ -132,8 +139,7 @@ void envquery(int argc, char **argv) strcat(rcfile, RCFILE_NAME); } -char *host_fqdn(void) -/* get the FQDN of the machine we're running */ +char *host_fqdn(int required) { char tmpbuf[HOSTLEN+1]; char *result; @@ -145,29 +151,37 @@ char *host_fqdn(void) exit(PS_DNS); } - /* if we got a . in the hostname assume it is a FQDN */ + /* if we got no . in the hostname, try to canonicalize it, + * else assume it is a FQDN */ if (strchr(tmpbuf, '.') == NULL) { - /* if we got a basename (as we do in Linux) make a FQDN of it */ - struct addrinfo hints, *res, *res0; + /* if we got a basename without dots, as we often do in Linux, + * look up canonical name (make a FQDN of it) */ + struct addrinfo hints, *res; int e; memset(&hints, 0, sizeof hints); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; - hints.ai_flags=AI_CANONNAME; + hints.ai_flags = AI_CANONNAME; - e = getaddrinfo(tmpbuf, NULL, &hints, &res); + e = fm_getaddrinfo(tmpbuf, NULL, &hints, &res); if (e) { /* exit with error message */ fprintf(stderr, GT_("gethostbyname failed for %s\n"), tmpbuf); fprintf(stderr, "%s", gai_strerror(e)); - exit(PS_DNS); + fprintf(stderr, GT_("Cannot find my own host in hosts database to qualify it!\n")); + if (required) + exit(PS_DNS); + else { + fprintf(stderr, GT_("Trying to continue with unqualified hostname.\nDO NOT report broken Received: headers, HELO/EHLO lines or similar problems!\nDO repair your /etc/hosts, DNS, NIS or LDAP instead.\n")); + return xstrdup(tmpbuf); + } } - result = xstrdup(res->ai_canonname); - freeaddrinfo(res); + result = xstrdup(res->ai_canonname ? res->ai_canonname : tmpbuf); + fm_freeaddrinfo(res); } else result = xstrdup(tmpbuf); @@ -280,9 +294,9 @@ char *visbuf(const char *buf) needed = strlen(buf) * 5 + 1; /* worst case: HEX, plus NUL byte */ - if (needed > vbufs) { + if (!vbuf || needed > vbufs) { vbufs = needed; - vbuf = xrealloc(vbuf, vbufs); + vbuf = (char *)xrealloc(vbuf, vbufs); } tp = vbuf; @@ -308,7 +322,7 @@ char *visbuf(const char *buf) buf++; } } - *tp++ = '\0'; + *tp = '\0'; return(vbuf); } /* env.c ends here */