From f931795fd8973c1edb40a26ecf87dbe27f7a6148 Mon Sep 17 00:00:00 2001 From: Ken Hornstein Date: Fri, 3 Feb 2012 23:43:53 -0500 Subject: [PATCH] Change LocalName() to take an argument (about whether or not to use local hostname versus entry in mts.conf). --- h/mts.h | 2 +- h/prototypes.h | 2 +- mts/smtp/hosts.c | 4 ++-- mts/smtp/smtp.c | 4 ++-- sbr/addrsbr.c | 10 +++++----- sbr/mts.c | 39 +++++++++++++++++++++++++-------------- uip/mhbuildsbr.c | 2 +- uip/mhlsbr.c | 4 ++-- uip/mhparse.c | 3 ++- uip/post.c | 8 ++++---- uip/sendsbr.c | 2 +- uip/viamail.c | 4 ++-- 12 files changed, 48 insertions(+), 36 deletions(-) diff --git a/h/mts.h b/h/mts.h index 2d2aa95..a8d795f 100644 --- a/h/mts.h +++ b/h/mts.h @@ -6,7 +6,7 @@ /* * Local and UUCP Host Name */ -char *LocalName(void); +char *LocalName(int); char *SystemName(void); /* diff --git a/h/prototypes.h b/h/prototypes.h index 12124cd..11db40d 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -133,7 +133,7 @@ int strncasecmp (const char *s1, const char *s2, size_t n); * some prototypes for address parsing system * (others are in addrsbr.h) */ -char *LocalName(void); +char *LocalName(int); char *SystemName(void); char *OfficialName(char *); diff --git a/mts/smtp/hosts.c b/mts/smtp/hosts.c index 29ac6d8..94a22d5 100644 --- a/mts/smtp/hosts.c +++ b/mts/smtp/hosts.c @@ -48,8 +48,8 @@ OfficialName (char *name) *q = '\0'; q = site; - if (!mh_strcasecmp (LocalName(), site)) - return LocalName(); + if (!mh_strcasecmp (LocalName(1), site)) + return LocalName(1); memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index ee98dce..faca17a 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -216,7 +216,7 @@ smtp_init (char *client, char *server, char *port, int watch, int verbose, if (clientname) { client = clientname; } else { - client = LocalName(); /* no clientname -> LocalName */ + client = LocalName(1); /* no clientname -> LocalName */ } } @@ -475,7 +475,7 @@ sendmail_init (char *client, char *server, int watch, int verbose, if (clientname) client = clientname; else - client = LocalName(); /* no clientname -> LocalName */ + client = LocalName(1); /* no clientname -> LocalName */ } /* diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index 07bc810..8a468bb 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -145,7 +145,7 @@ getm (char *str, char *dfhost, int dftype, int wanthost, char *eresult) } if (dfhost == NULL) { - dfhost = LocalName (); + dfhost = LocalName (0); dftype = LOCALHOST; } @@ -202,10 +202,10 @@ getm (char *str, char *dfhost, int dftype, int wanthost, char *eresult) } if (wanthost == AD_NHST) - mp->m_type = !mh_strcasecmp (LocalName (), mp->m_host) + mp->m_type = !mh_strcasecmp (LocalName (0), mp->m_host) ? LOCALHOST : NETHOST; else - mp->m_type = mh_strcasecmp (LocalName(), mp->m_host) ? NETHOST : LOCALHOST; + mp->m_type = mh_strcasecmp (LocalName(0), mp->m_host) ? NETHOST : LOCALHOST; got_host: ; if (route) @@ -327,7 +327,7 @@ getlocaladdr(void) return username; - domain = LocalName(); + domain = LocalName(0); snprintf_return = snprintf (addr, sizeof(addr), "%s@%s", username, domain); @@ -419,7 +419,7 @@ ismymbox (struct mailname *np) switch (np->m_type) { case NETHOST: - len = strlen (cp = LocalName ()); + len = strlen (cp = LocalName (0)); if (!uprf (np->m_host, cp) || np->m_host[len] != '.') break; goto local_test; diff --git a/sbr/mts.c b/sbr/mts.c index 834579d..451a9b2 100644 --- a/sbr/mts.c +++ b/sbr/mts.c @@ -78,7 +78,7 @@ char *sendmail = SENDMAILPATH; * SMTP/POP stuff */ char *clientname = NULL; -char *servers = "localhost \01localnet"; +char *servers = "localhost"; char *pophost = ""; /* @@ -238,34 +238,45 @@ tailor_value (unsigned char *s) /* * Get the fully qualified name of the local host. + * + * If flag is 0, then use anything out of mts.conf (like localname). + * If flag is 1, then only use the "proper" local hostname. */ char * -LocalName (void) +LocalName (int flag) { - static char buffer[BUFSIZ] = ""; + static char buffer0[BUFSIZ] = ""; + static char buffer1[BUFSIZ] = ""; + static char *buffer[] = { buffer0, buffer1 }; + char *buf; struct addrinfo hints, *res; + if (flag < 0 || flag > 1) + return NULL; + + buf = buffer[flag]; + /* check if we have cached the local name */ - if (buffer[0]) - return buffer; + if (buf[0]) + return buf; mts_init ("mts"); /* check if the mts.conf file specifies a "localname" */ - if (*localname) { - strncpy (buffer, localname, sizeof(buffer)); + if (*localname && flag == 0) { + strncpy (buf, localname, sizeof(buffer0)); } else { - memset(buffer, 0, sizeof(buffer)); + memset(buffer, 0, sizeof(buffer0)); /* first get our local name */ - gethostname (buffer, sizeof(buffer) - 1); + gethostname (buf, sizeof(buffer0) - 1); /* now fully qualify our name */ memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; hints.ai_family = PF_UNSPEC; - if (getaddrinfo(buffer, NULL, &hints, &res) == 0) { - strncpy(buffer, res->ai_canonname, sizeof(buffer) - 1); + if (getaddrinfo(buf, NULL, &hints, &res) == 0) { + strncpy(buf, res->ai_canonname, sizeof(buffer0) - 1); freeaddrinfo(res); } } @@ -275,11 +286,11 @@ LocalName (void) * we append that now. This should rarely be needed. */ if (*localdomain) { - strcat (buffer, "."); - strcat (buffer, localdomain); + strcat (buf, "."); + strcat (buf, localdomain); } - return buffer; + return buf; } diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 2a3f899..c349bf8 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -859,7 +859,7 @@ set_id (CT ct, int top) if (clock == 0) { time (&clock); snprintf (msgid, sizeof(msgid), "<%d.%ld.%%d@%s>\n", - (int) getpid(), (long) clock, LocalName()); + (int) getpid(), (long) clock, LocalName(1)); partno = 0; msgfmt = getcpy(msgid); } diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index eef0937..6bfbade 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1096,7 +1096,7 @@ mcomp_format (struct mcomp *c1, struct mcomp *c2) if ((c1->c_flags & FACEDFLT) && c2->c_face == NULL) { char *h, *o; if ((h = mp->m_host) == NULL) - h = LocalName (); + h = LocalName (0); if ((o = OfficialName (h))) h = o; c2->c_face = concat ("address ", h, " ", mp->m_mbox, @@ -1503,7 +1503,7 @@ face_format (struct mcomp *c1) if ((mp = getm (cp, NULL, 0, AD_NAME, NULL))) { char *h, *o; if ((h = mp->m_host) == NULL) - h = LocalName (); + h = LocalName (0); if ((o = OfficialName (h))) h = o; c1->c_face = concat ("address ", h, " ", mp->m_mbox, NULL); diff --git a/uip/mhparse.c b/uip/mhparse.c index e151062..5b48483 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -2554,7 +2554,8 @@ openFTP (CT ct, char **file) if (e->eb_flags) { user = "anonymous"; - snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), LocalName ()); + snprintf (buffer, sizeof(buffer), "%s@%s", getusername (), + LocalName (1)); pass = buffer; } else { ruserpass (e->eb_site, &username, &password); diff --git a/uip/post.c b/uip/post.c index dcd563b..580d3d1 100644 --- a/uip/post.c +++ b/uip/post.c @@ -869,7 +869,7 @@ start_headers (void) time (&tclock); strncpy (from, getlocaladdr(), sizeof(from)); - strncpy (myhost, LocalName (), sizeof(myhost)); + strncpy (myhost, LocalName (0), sizeof(myhost)); for (cp = myhost; *cp; cp++) *cp = uptolow (*cp); @@ -908,7 +908,7 @@ finish_headers (FILE *out) fprintf (out, "Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MFRM) { /* There was already a From: in the draft. Don't add one. */ if (!draft_from_masquerading) @@ -943,7 +943,7 @@ finish_headers (FILE *out) fprintf (out, "Resent-Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Resent-Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MRFM) { /* There was already a Resent-From: in draft. Don't add one. */ if (!draft_from_masquerading) @@ -1197,7 +1197,7 @@ make_bcc_file (int dashstuff) fprintf (out, "Date: %s\n", dtime (&tclock, 0)); if (msgid) fprintf (out, "Message-ID: <%d.%ld@%s>\n", - (int) getpid (), (long) tclock, LocalName ()); + (int) getpid (), (long) tclock, LocalName (1)); if (msgflags & MFRM) { /* There was already a From: in the draft. Don't add one. */ if (!draft_from_masquerading) diff --git a/uip/sendsbr.c b/uip/sendsbr.c index f216e95..04d6ea9 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -669,7 +669,7 @@ splitmsg (char **vec, int vecp, char *drft, struct stat *st, int delay) time (&clock); snprintf (msgid, sizeof(msgid), "<%d.%ld@%s>", - (int) getpid(), (long) clock, LocalName()); + (int) getpid(), (long) clock, LocalName(1)); fseek (in, start, SEEK_SET); for (partno = 1; partno <= nparts; partno++) { diff --git a/uip/viamail.c b/uip/viamail.c index 2e1c51c..49bbdf4 100644 --- a/uip/viamail.c +++ b/uip/viamail.c @@ -185,7 +185,7 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw, strncpy (tmpfil, tfile, sizeof(tmpfil)); if (!strchr(mailsw, '@')) - mailsw = concat (mailsw, "@", LocalName (), NULL); + mailsw = concat (mailsw, "@", LocalName (0), NULL); fprintf (fp, "To: %s\n", mailsw); if (subjsw) @@ -193,7 +193,7 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw, if (fromsw) { if (!strchr(fromsw, '@')) - fromsw = concat (fromsw, "@", LocalName (), NULL); + fromsw = concat (fromsw, "@", LocalName (0), NULL); fprintf (fp, "From: %s\n", fromsw); } -- 1.7.10.4