Date: Tue, 24 Oct 2000 21:15:18 +0200 From: Jeroen Ruigrok van der Werven <jruigrok@via-net-works.nl> To: Guido van Rooij <guido@gvr.org> Cc: audit@FreeBSD.ORG Subject: Re: printjob.c mktemp() problem Message-ID: <20001024211518.E209@lucifer.bart.nl> In-Reply-To: <20001024202942.C209@lucifer.bart.nl>; from jruigrok@via-net-works.nl on Tue, Oct 24, 2000 at 08:29:42PM %2B0200 References: <20001024140510.G93799@lucifer.bart.nl> <20001024170054.Q93799@lucifer.bart.nl> <20001024192539.A65599@gvr.gvr.org> <20001024202942.C209@lucifer.bart.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--Pd0ReVV5GZGQvF3a Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -On [20001024 20:35], Jeroen Ruigrok van der Werven (jruigrok@via-net-works.nl) wrote: >-On [20001024 19:30], Guido van Rooij (guido@gvr.org) wrote: >>You should remove the addition of int i = -1 since it isn't used. > >Yeah, I fixed that in my latest patches. Deleted bogus assignment of i = fchmod(). No need for it. >I still need to look at Garance's mention of the tempfile name which >doesn't include a /tmp/ path. My new patch should also fix this case. Given that lpd is a daemon I didn't use warnx/errx but instead used syslog(), but it might be that some logging is not yet fully clear what went wrong with my patch. I'll try to test that tomorrow. I haven't sanitized the code further except make my changes as sane possible as I could by myself and guidance from my mentors and peers. Opinions welcome. -- Jeroen Ruigrok van der Werven Network- and systemadministrator <jruigrok@via-net-works.nl> VIA Net.Works The Netherlands BSD: Technical excellence at its best http://www.via-net-works.nl I'm a child of the air, I'm a witch of the wind... --Pd0ReVV5GZGQvF3a Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="printjob.c.diff" --- printjob.c.orig Tue Oct 24 15:38:17 2000 +++ printjob.c Tue Oct 24 21:13:29 2000 @@ -114,7 +114,7 @@ static char logname[32]; /* user's login name */ static char pxlength[10] = "-y"; /* page length in pixels */ static char pxwidth[10] = "-x"; /* page width in pixels */ -static char tempfile[] = "errsXXXXXX"; /* file name for filter errors */ +static char *tempfile; /* file name for filter errors */ static char width[10] = "-w"; /* page width in static characters */ #define TFILENAME "fltXXXXXX" static char tfile[] = TFILENAME; /* file name for filter output */ @@ -153,6 +153,13 @@ off_t pidoff; int errcnt, count = 0; + if (getenv("TMPDIR") == NULL) + tempfile = strdup("/tmp/errsXXXXXXXXX"); + else + if (asprintf(&tempfile, "%s/errsXXXXXXXXX", + getenv("TMPDIR")) == -1) + syslog(LOG_ERR, "asprintf: %m"); + init(pp); /* set up capabilities */ (void) write(1, "", 1); /* ack that daemon is started */ (void) close(2); /* set up log file */ @@ -168,8 +175,6 @@ signal(SIGQUIT, abortpr); signal(SIGTERM, abortpr); - (void) mktemp(tempfile); - /* * uses short form file names */ @@ -733,9 +738,15 @@ if ((child = dofork(pp, DORETURN)) == 0) { /* child */ dup2(fi, 0); dup2(fo, 1); - n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, 0664); - if (n >= 0) - dup2(n, 2); + if ((n = mkstemp(tempfile)) == -1) { + syslog(LOG_ERR, "mkstemp: %m"); + exit(-1); + } + if ((fchmod(n, 0664)) == -1) { /* O660 should also work */ + syslog(LOG_ERR, "fchmod: %m"); + exit(-1); + } + dup2(n, 2); closelog(); closeallfds(3); execv(prog, av); @@ -953,10 +964,15 @@ if ((ifilter = dofork(pp, DORETURN)) == 0) { /* child */ dup2(f, 0); dup2(tfd, 1); - n = open(tempfile, O_WRONLY|O_CREAT|O_TRUNC, - TEMP_FILE_MODE); - if (n >= 0) - dup2(n, 2); + if ((n = mkstemp(tempfile)) == -1) { + syslog(LOG_ERR, "mkstemp: %m"); + exit(-1); + } + if ((fchmod(n, 0664)) == -1) { + syslog(LOG_ERR, "fchmod: %m"); + exit(-1); + } + dup2(n, 2); closelog(); closeallfds(3); execv(pp->filters[LPF_INPUT], av); @@ -1329,7 +1345,7 @@ */ if (pid == 0) { if ((pwd = getpwuid(pp->daemon_user)) == NULL) { - syslog(LOG_ERR, "Can't lookup default daemon uid (%d) in password file", + syslog(LOG_ERR, "Can't lookup default daemon uid (%ld) in password file", pp->daemon_user); break; } --Pd0ReVV5GZGQvF3a-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001024211518.E209>