Path: utzoo!utstat!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!ucsd!dog.ee.lbl.gov!ace.ee.lbl.gov!leres From: leres@ace.ee.lbl.gov (Craig Leres) Newsgroups: news.software.nntp Subject: Re: environ and myenviron Message-ID: <8174@dog.ee.lbl.gov> Date: 20 Nov 90 21:55:04 GMT References: <1990Nov20.124248.13617@dutlru1.tudelft.nl> Sender: usenet@dog.ee.lbl.gov Reply-To: leres@helios.ee.lbl.gov (ucbvax!leres for uucp weenies) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 141 X-Local-Date: Tue, 20 Nov 90 13:55:04 PST I originally added this code to keep the SETPROCTITLE from trashing the environment and really screwing up the child. But as Ge van Geldorp points out, it breaks putenv(). And in fact, blindly passing the environment to the child causes other problems (when you have cnews, anyway). For example if I run nntp standalone and start it up while su'ed to root from my normal account, postings that show up without a From or Sender go out looking like I posted them since USER points to me. (It can be pretty amusing when your buddies start asking you about your recent posting to soc.feminism or whatever.) The code I've been running for a few months now either gives the child a null environment or defines USER and LOGNAME to POSTER. For the adventurous, I've appended context diffs to batch.c and spawn.c. Craig ------ hell 55 % rcsdiff -c -r1.10 -r1.11 batch.c *** /tmp/,RCSt1a21666 Tue Nov 20 13:40:15 1990 --- /tmp/,RCSt2a21666 Tue Nov 20 13:40:17 1990 *************** *** 30,36 **** /* imports */ extern time_t time(); extern char *malloc(), *mktemp(), *index(), *rindex(); - extern char **myenviron; /* forwards */ static char *strsave(); --- 30,35 ---- *************** *** 344,349 **** --- 343,353 ---- int pid, wpid, status, fd, exitstat; char permname[MAXDIGITS], *number = permname, *newsrun; struct stat stbuf; + #ifdef POSTER + char *envp[3], user[sizeof(POSTER) + 5], logname[sizeof(POSTER) + 8]; + #else + char *envp[1]; + #endif (void) fclose(btch.file); btch.file = NULL; *************** *** 417,423 **** newsrun = strsave(NEWSRUN); if (newsrun == NULL) newsrun = "/usr/lib/newsbin/input/newsrun"; ! execle(newsrun, newsrun, (char *)NULL, myenviron); #ifdef SYSLOG syslog(LOG_ERR, "enqueue: execle(%s): %m", newsrun); #endif --- 421,439 ---- newsrun = strsave(NEWSRUN); if (newsrun == NULL) newsrun = "/usr/lib/newsbin/input/newsrun"; ! ! /* Empty environment keeps cnews inews from telling lies */ ! #ifdef POSTER ! sprintf(user, "USER=%s", POSTER); ! sprintf(logname, "LOGNAME=%s", POSTER); ! envp[0] = user; ! envp[1] = logname; ! envp[2] = 0; ! #else ! envp[0] = 0; ! #endif ! ! execle(newsrun, newsrun, (char *)NULL, envp); #ifdef SYSLOG syslog(LOG_ERR, "enqueue: execle(%s): %m", newsrun); #endif *************** *** 424,429 **** --- 440,446 ---- exit(1); /* NOTREACHED */ } + static char * strsave(s) register char *s; hell 56 % rcsdiff -c -r1.9 -r1.10 *** /tmp/,RCSt1a21687 Tue Nov 20 13:40:39 1990 --- /tmp/,RCSt2a21687 Tue Nov 20 13:40:41 1990 *************** *** 13,21 **** static int old_xfer_lines; #endif - /* imports */ - extern char **myenviron; - static char tempfile[256]; #ifndef CNEWS static char badfile[256]; --- 13,18 ---- *************** *** 57,62 **** --- 54,64 ---- int fds[2]; int pid, npid; int exit_status; + #ifdef POSTER + char *envp[3], user[sizeof(POSTER) + 5], logname[sizeof(POSTER) + 8]; + #else + char *envp[1]; + #endif #ifdef XFER_TIMEOUT int xfer_timeout(); #endif *************** *** 194,200 **** (void) close(fd); } ! execle(path, name, flag, (char *) NULL, myenviron); fprintf(stderr, "spawn: execle(%s)", path); perror(path); #ifdef SYSLOG --- 196,213 ---- (void) close(fd); } ! /* Empty environment keeps cnews inews from telling lies */ ! #ifdef POSTER ! sprintf(user, "USER=%s", POSTER); ! sprintf(logname, "LOGNAME=%s", POSTER); ! envp[0] = user; ! envp[1] = logname; ! envp[2] = 0; ! #else ! envp[0] = 0; ! #endif ! ! execle(path, name, flag, (char *) NULL, envp); fprintf(stderr, "spawn: execle(%s)", path); perror(path); #ifdef SYSLOG