🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #792

Re: environ and myenviron

#792
From: Craig Leres
Date: Tue, 20 Nov 1990 21:55
142 lines
4592 bytes
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
Technical Details
Message-ID: <8174@dog.ee.lbl.gov>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utstat!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!ucsd!dog.ee.lbl.gov!ace.ee.lbl.gov!leres
References: <1990Nov20.124248.13617@dutlru1.tudelft.nl>

Show Full Headers
Complete Article Headers
Message-ID: <8174@dog.ee.lbl.gov>
Subject: Re: environ and myenviron
Date: Tue, 20 Nov 1990 21:55:04 +0000
From: leres@ace.ee.lbl.gov (Craig Leres)
References: <1990Nov20.124248.13617@dutlru1.tudelft.nl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp!utzoo!utstat!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!ucsd!dog.ee.lbl.gov!ace.ee.lbl.gov!leres
Newsgroups: news.software.nntp
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