]> Pileus Git - ~andy/fetchmail/blobdiff - env.c
Added URL.
[~andy/fetchmail] / env.c
diff --git a/env.c b/env.c
index 06f9da672aaa81f098136d318f1e3515a0aaca2e..16254ddd7ce0d87cc294317f9b690d43918c3aad 100644 (file)
--- a/env.c
+++ b/env.c
@@ -7,6 +7,7 @@
 #include "config.h"
 #include "fetchmail.h"
 #include <stdio.h>
+#include <ctype.h>
 #if defined(STDC_HEADERS)
 #include <stdlib.h>
 #endif
 
 extern char *getenv(); /* needed on sysV68 R3V7.1. */
 
-char *user, *home, *fetchmailhost;
-
 extern char *program_name;
 
 void envquery(int argc, char **argv)
 /* set up basic stuff from the environment (including the rc file name) */
 {
-    char *tmpdir, tmpbuf[BUFSIZ]; 
+    char tmpbuf[BUFSIZ]; 
     struct passwd *pw;
-    struct query *ctl;
 
     if ((program_name = strrchr(argv[0], '/')) != NULL)
        ++program_name;
@@ -57,36 +55,52 @@ void envquery(int argc, char **argv)
        }
     }
 
-    /* we'll need this for the SMTP forwarding target and error messages */
+#define RCFILE_NAME    ".fetchmailrc"
+    rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
+    /* avoid //.fetchmailrc */
+    if (strcmp(home, "/") != 0) {
+       strcpy(rcfile, home);
+    } else {
+       *rcfile = '\0';
+    }
+    strcat(rcfile, "/");
+    strcat(rcfile, RCFILE_NAME);
+}
+
+char *host_fqdn(void)
+/* get the FQDN of the machine we're running */
+{
+    char       tmpbuf[HOSTLEN+1];
+
     if (gethostname(tmpbuf, sizeof(tmpbuf)))
     {
-       fprintf(stderr, "%s: can't determine your host!", program_name);
-       exit(PS_IOERR);
+       fprintf(stderr, "%s: can't determine your host!",
+               program_name);
+       exit(PS_DNS);
     }
 #ifdef HAVE_GETHOSTBYNAME
+    /* if we got a . in the hostname assume it is a FQDN */
+    if (strchr(tmpbuf, '.') == NULL)
     {
        struct hostent *hp;
 
-       /* in case we got a basename (as we do in Linux) make a FQDN of it */
+       /* if we got a basename (as we do in Linux) make a FQDN of it */
        hp = gethostbyname(tmpbuf);
        if (hp == (struct hostent *) NULL)
        {
            /* exit with error message */
-           fprintf(stderr, "gethostbyname failed for %s", tmpbuf);
+           fprintf(stderr,
+                   "gethostbyname failed for %s\n", tmpbuf);
            exit(PS_DNS);
        }
-       strcpy(tmpbuf, hp->h_name);
+       return(xstrdup(hp->h_name));
     }
+    else
 #endif /* HAVE_GETHOSTBYNAME */
-    fetchmailhost = xstrdup(tmpbuf);
-
-#define RCFILE_NAME    ".fetchmailrc"
-    rcfile = (char *) xmalloc(strlen(home)+strlen(RCFILE_NAME)+2);
-    strcpy(rcfile, home);
-    strcat(rcfile, "/");
-    strcat(rcfile, RCFILE_NAME);
+       return(xstrdup(tmpbuf));
 }
 
+
 char *showproto(int proto)
 /* protocol index to protocol name mapping */
 {
@@ -99,6 +113,9 @@ char *showproto(int proto)
     case P_POP3: return("POP3"); break;
     case P_IMAP: return("IMAP"); break;
     case P_IMAP_K4: return("IMAP-K4"); break;
+#ifdef GSSAPI
+    case P_IMAP_GSS: return("IMAP-GSS"); break;
+#endif /* GSSAPI */
     case P_APOP: return("APOP"); break;
     case P_RPOP: return("RPOP"); break;
     case P_ETRN: return("ETRN"); break;
@@ -114,7 +131,12 @@ char *visbuf(const char *buf)
 
     while (*buf)
     {
-       if (isprint(*buf) || *buf == ' ')
+       if (*buf == '"')
+       {
+           *tp++ = '\\'; *tp++ = '"';
+           buf++;
+       }
+       else if (isprint(*buf) || *buf == ' ')
            *tp++ = *buf++;
        else if (*buf == '\n')
        {