From 14e29bd901c560cf0848593e854368b04b4643c2 Mon Sep 17 00:00:00 2001 From: Eric Allman Date: Mon, 15 May 1995 22:38:59 -0800 Subject: [PATCH] improved implementation for E line -- slightly cleaner -- plus resulting simplifications in map.c for NIS+ SCCS-vsn: usr.sbin/sendmail/src/main.c 8.108 SCCS-vsn: usr.sbin/sendmail/src/map.c 8.60 --- usr/src/usr.sbin/sendmail/src/main.c | 31 +++++++++++----------- usr/src/usr.sbin/sendmail/src/map.c | 39 +++++----------------------- 2 files changed, 21 insertions(+), 49 deletions(-) diff --git a/usr/src/usr.sbin/sendmail/src/main.c b/usr/src/usr.sbin/sendmail/src/main.c index 28d486f4fc..861ed17da2 100644 --- a/usr/src/usr.sbin/sendmail/src/main.c +++ b/usr/src/usr.sbin/sendmail/src/main.c @@ -13,7 +13,7 @@ static char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)main.c 8.107 (Berkeley) %G%"; +static char sccsid[] = "@(#)main.c 8.108 (Berkeley) %G%"; #endif /* not lint */ #define _DEFINE @@ -298,6 +298,9 @@ main(argc, argv, envp) for (i = 0; envp[i] != NULL; i++) environ[i] = newstr(envp[i]); + /* and prime the child environment */ + setuserenv("AGENT", "sendmail"); + /* ** Save start and extent of argv for setproctitle. */ @@ -824,15 +827,10 @@ main(argc, argv, envp) setbitn(M_RUNASRCPT, FileMailer->m_flags); /* propogate some envariables into children */ - setuserenv("AGENT", "sendmail"); setuserenv("ISP", NULL); setuserenv("SYSTYPE", NULL); } - /* guarantee non-empty environment to children */ - if (UserEnviron[0] == NULL) - setuserenv("AGENT", "sendmail"); - /* MIME Content-Types that cannot be transfer encoded */ setclass('n', "multipart/signed"); @@ -1493,7 +1491,7 @@ setuserenv(envar, value) { int i; char **evp = UserEnviron; - char buf[100]; + char *p; if (value == NULL) { @@ -1503,24 +1501,25 @@ setuserenv(envar, value) } i = strlen(envar); - if (i + strlen(value) > sizeof buf - 2) - return; + p = (char *) xalloc(strlen(value) + i + 2); + strcpy(p, envar); + p[i++] = '='; + strcpy(&p[i], value); - strcpy(buf, envar); - buf[i++] = '='; - strcpy(&buf[i], value); - - while (*evp != NULL && strncmp(*evp, buf, i) != 0) + while (*evp != NULL && strncmp(*evp, p, i) != 0) evp++; if (*evp != NULL) { - *evp++ = newstr(buf); + *evp++ = p; } else if (evp < &UserEnviron[MAXUSERENVIRON]) { - *evp++ = newstr(buf); + *evp++ = p; *evp = NULL; } + + /* make sure it is in our environment as well */ + putenv(p); } /* ** DUMPSTATE -- dump state diff --git a/usr/src/usr.sbin/sendmail/src/map.c b/usr/src/usr.sbin/sendmail/src/map.c index 6d603ae12d..0fedcfa052 100644 --- a/usr/src/usr.sbin/sendmail/src/map.c +++ b/usr/src/usr.sbin/sendmail/src/map.c @@ -7,7 +7,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)map.c 8.59 (Berkeley) %G%"; +static char sccsid[] = "@(#)map.c 8.60 (Berkeley) %G%"; #endif /* not lint */ #include "sendmail.h" @@ -1540,48 +1540,24 @@ nisplus_getcanonname(name, hbsize, statp) char *vp; auto int vsize; int buflen; - char buf1[MAXLINE + NIS_MAXNAMELEN]; - static char *nis_path = NULL; - static char nis_path_buf[MAXLINE]; + char buf[MAXLINE + NIS_MAXNAMELEN]; nis_result *result; char *p; int len; - if (nis_path == NULL) - { - char *ptr; - char pathbuf[MAXLINE]; - - strcpy(buf1, macvalue('m', CurEnv)); - strcat(buf1, "."); - /* try the host tabe in $m */ - if (hosts_table_ok(buf1)) - strcpy(pathbuf, buf1); - else - strcpy(pathbuf, "$"); - - nis_path = nis_path_buf; - sprintf(nis_path, "NIS_PATH=%s", pathbuf); - } - - if (nis_path[0] != '\0') - putenv(nis_path); - else - syslog(LOG_WARNING, "no NIS+ path defined"); - shorten_hostname(name); p = strchr(name, '.'); if (p == NULL) { /* single token */ - sprintf(buf1, "[name=%s],hosts.org_dir", name); + sprintf(buf, "[name=%s],hosts.org_dir", name); } else if (p[1] != '\0') { /* multi token -- take only first token in name buf */ *p = '\0'; - sprintf(buf1, "[name=%s],hosts.org_dir.%s", name, &p[1]); + sprintf(buf, "[name=%s],hosts.org_dir.%s", name, &p[1]); } else { @@ -1591,14 +1567,11 @@ nisplus_getcanonname(name, hbsize, statp) if (tTd(38, 20)) printf("\nnisplus_getcanoname(%s), qbuf=%s\n%s\n", - name, buf1, nis_path); + name, buf, nis_path); - result = nis_list(buf1, EXPAND_NAME|FOLLOW_LINKS|FOLLOW_PATH, + result = nis_list(buf, EXPAND_NAME|FOLLOW_LINKS|FOLLOW_PATH, NULL, NULL); - /* unset NIS_PATH, just in case */ - unsetenv("NIS_PATH"); - if (result->status == NIS_SUCCESS) { int count; -- 2.20.1