From nobody@FreeBSD.org  Sun Aug  7 01:35:50 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0FF92106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  7 Aug 2011 01:35:50 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 005598FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Sun,  7 Aug 2011 01:35:50 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p771ZnvN006976
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 7 Aug 2011 01:35:49 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p771ZnHI006975;
	Sun, 7 Aug 2011 01:35:49 GMT
	(envelope-from nobody)
Message-Id: <201108070135.p771ZnHI006975@red.freebsd.org>
Date: Sun, 7 Aug 2011 01:35:49 GMT
From: Aragon Gouveia <aragon@phat.za.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] allow daemon(8) to write pid file in /var/run without root
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         159568
>Category:       bin
>Synopsis:       [patch] allow daemon(8) to write pid file in /var/run without root
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 07 01:40:12 UTC 2011
>Closed-Date:    Thu Jan 05 16:50:02 CST 2012
>Last-Modified:  Thu Jan  5 22:50:11 UTC 2012
>Originator:     Aragon Gouveia
>Release:        8.2-RELEASE-p2
>Organization:
>Environment:
FreeBSD fuzz.geek.sh 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0: Sun Jul 10 15:27:35 SAST 2011     toor@igor.geek.sh:/usr/obj/usr/src-RELENG_8_2/sys/FUZZ  amd64

>Description:
daemon(8) provides the ability to write a pid file of the daemon it forks.  It also provides the ability to drop root privileges of the daemon it forks, however, this feature prevents it from writing a pid file to /var/run.

Attached patch makes daemon(8) open the pid file descriptor before dropping root privileges.

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- daemon.c.orig	2011-08-07 03:26:47.000000000 +0200
+++ daemon.c	2011-08-07 03:27:04.000000000 +0200
@@ -79,9 +79,6 @@
 	if (argc == 0)
 		usage();
 
-	if (user != NULL)
-		restrict_process(user);
-
 	/*
 	 * Try to open the pidfile before calling daemon(3),
 	 * to be able to report the error intelligently
@@ -97,6 +94,9 @@
 		}
 	}
 
+	if (user != NULL)
+		restrict_process(user);
+
 	if (daemon(nochdir, noclose) == -1)
 		err(1, NULL);
 


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ghelmer 
State-Changed-When: Thu Jan 5 16:49:32 CST 2012 
State-Changed-Why:  
Makes sense to me -- patch applied. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=159568 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/159568: commit references a PR
Date: Thu,  5 Jan 2012 22:48:46 +0000 (UTC)

 Author: ghelmer
 Date: Thu Jan  5 22:48:36 2012
 New Revision: 229667
 URL: http://svn.freebsd.org/changeset/base/229667
 
 Log:
   Allow daemon(8) to run pidfile_open() before relenquishing privileges
   so pid files can be written in /var/run when started as root.
   
   I do not expect this to cause any security issues, but if anyone objects
   it could be easily reverted.
   
   PR:		bin/159568
   MFC after:	4 weeks
 
 Modified:
   head/usr.sbin/daemon/daemon.c
 
 Modified: head/usr.sbin/daemon/daemon.c
 ==============================================================================
 --- head/usr.sbin/daemon/daemon.c	Thu Jan  5 22:31:25 2012	(r229666)
 +++ head/usr.sbin/daemon/daemon.c	Thu Jan  5 22:48:36 2012	(r229667)
 @@ -79,9 +79,6 @@ main(int argc, char *argv[])
  	if (argc == 0)
  		usage();
  
 -	if (user != NULL)
 -		restrict_process(user);
 -
  	/*
  	 * Try to open the pidfile before calling daemon(3),
  	 * to be able to report the error intelligently
 @@ -97,6 +94,9 @@ main(int argc, char *argv[])
  		}
  	}
  
 +   if (user != NULL)
 +             restrict_process(user);
 +
  	if (daemon(nochdir, noclose) == -1)
  		err(1, NULL);
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
