From nobody@FreeBSD.org  Fri Jul 27 02:52:34 2007
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 B465716A417
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Jul 2007 02:52:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 9840113C467
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Jul 2007 02:52:34 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.1/8.14.1) with ESMTP id l6R2qYTJ083327
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 27 Jul 2007 02:52:34 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.1/8.14.1/Submit) id l6R2qYrm083325;
	Fri, 27 Jul 2007 02:52:34 GMT
	(envelope-from nobody)
Message-Id: <200707270252.l6R2qYrm083325@www.freebsd.org>
Date: Fri, 27 Jul 2007 02:52:34 GMT
From: Chris Cowart <ccowart@rescomp.berkeley.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: net-mgmt/net-snmp4 rc script starts snmpd without being enabled
X-Send-Pr-Version: www-3.0

>Number:         114952
>Category:       ports
>Synopsis:       net-mgmt/net-snmp4 rc script starts snmpd without being enabled
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    rafan
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul 27 03:00:02 GMT 2007
>Closed-Date:    Fri Jul 27 11:59:42 GMT 2007
>Last-Modified:  Fri Jul 27 12:00:01 GMT 2007
>Originator:     Chris Cowart
>Release:        6.2_REL
>Organization:
RSSP-IT, UC Berkeley
>Environment:
FreeBSD stingray.rescomp.berkeley.edu 6.2-RELEASE-p4 FreeBSD 6.2-RELEASE-p4 #0: Mon May 21 21:36:00 PDT 2007     root@stingray.rescomp.berkeley.edu:/usr/obj/usr/src/sys/RCBSD_1  i386

>Description:
I'm referring to the port Makefile with FreeBSD Id:
$FreeBSD: ports/net-mgmt/net-snmp4/Makefile,v 1.105 2007/06/21 06:59:36 rafan Exp $

Line 139 of the Makefile installs files/snmpd.sh.sample into /usr/local/etc/rc.d/snmpd.sh.

This is *not* a FreeBSD-style rc script. It simply switches on "$1" for the word start or stop and performs that action. It does *not* use /etc/rc.subr to determine whether snmpd has been enabled. 

As a result, snmpd will be started during boot on any machine where the port net-mgmt/net-snmp4 is installed. Some would consider this to be a security problem.
>How-To-Repeat:

>Fix:
I've included a patch that creates a FreeBSD-style rc script in files and updates the port to install it.

Patch attached with submission follows:

diff -Nrub net-snmp4-orig/Makefile net-snmp4-mine/Makefile
--- net-snmp4-orig/Makefile	2007-07-26 18:02:09.000000000 -0700
+++ net-snmp4-mine/Makefile	2007-07-26 17:59:24.000000000 -0700
@@ -82,7 +82,7 @@
 		snmpstatus snmptest snmptranslate snmptrap snmpwalk
 SBIN=		snmpd snmptrapd
 
-STARTUP_FILE=	${PREFIX}/etc/rc.d/snmpd.sh
+STARTUP_FILE=	${PREFIX}/etc/rc.d/snmpd
 
 CONFLICTS=	net-snmp-5.*
 
@@ -135,8 +135,8 @@
 	@for F in ${WRKSRC}/EXAMPLE.conf  ${WRKSRC}/agent/mibgroup/examples/ucdDemoPublic.conf; do \
 		${INSTALL_DATA} $$F ${PREFIX}/share/examples/ucd-snmp ; done
 	@if [ ! -f ${STARTUP_FILE} ]; then \
-		${ECHO} "Creating ${PREFIX}/etc/rc.d/snmpd.sh startup file."; \
-		${INSTALL_SCRIPT} -m 751 ${FILESDIR}/snmpd.sh.sample ${STARTUP_FILE}; \
+		${ECHO} "Creating ${STARTUP_FILE} startup file."; \
+		${INSTALL_SCRIPT} -m 755 ${FILESDIR}/snmpd ${STARTUP_FILE}; \
 	 fi
 
 .include <bsd.port.post.mk>
diff -Nrub net-snmp4-orig/files/snmpd net-snmp4-mine/files/snmpd
--- net-snmp4-orig/files/snmpd	1969-12-31 16:00:00.000000000 -0800
+++ net-snmp4-mine/files/snmpd	2007-07-26 18:00:37.000000000 -0700
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+# PROVIDE: snmpd
+# REQUIRE: DAEMON
+#
+# Add the following line to /etc/rc.conf to enable snmpd:
+#
+# snmpd_enable="YES"
+#
+
+snmpd_enable=${snmpd_enable:-"NO"}
+snmpd_flags=${snmpd_flags:-"-p /var/run/snmpd.pid"}
+
+. /etc/rc.subr
+
+name=snmpd
+rcvar=`set_rcvar`
+
+command=/usr/local/sbin/${name}
+pidfile=/var/run/${name}.pid
+
+load_rc_config ${name}
+run_rc_command "$1"
diff -Nrub net-snmp4-orig/pkg-plist net-snmp4-mine/pkg-plist
--- net-snmp4-orig/pkg-plist	2007-07-26 17:48:02.000000000 -0700
+++ net-snmp4-mine/pkg-plist	2007-07-26 18:02:23.000000000 -0700
@@ -19,7 +19,7 @@
 bin/snmpusm
 bin/snmpvacm
 bin/snmpwalk
-etc/rc.d/snmpd.sh
+etc/rc.d/snmpd
 include/ucd-snmp/agent_index.h
 include/ucd-snmp/agent_read_config.h
 include/ucd-snmp/agent_registry.h


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->rafan 
Responsible-Changed-By: rafan 
Responsible-Changed-When: Fri Jul 27 11:43:31 UTC 2007 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=114952 
State-Changed-From-To: open->closed 
State-Changed-By: rafan 
State-Changed-When: Fri Jul 27 11:59:41 UTC 2007 
State-Changed-Why:  
Committed with changes. Thanks. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/114952: commit references a PR
Date: Fri, 27 Jul 2007 11:59:34 +0000 (UTC)

 rafan       2007-07-27 11:59:29 UTC
 
   FreeBSD ports repository
 
   Modified files:
     net-mgmt/net-snmp4   Makefile pkg-plist 
   Added files:
     net-mgmt/net-snmp4/files snmpd.in 
   Removed files:
     net-mgmt/net-snmp4/files snmpd.sh.sample 
   Log:
   - Convert to rc.d style script
   - Bump PORTREVISION
   
   Note that I changed few places of the patch to match Porter's Handbook.
   
   PR:             ports/114952
   Submitted by:   Chris Cowart <ccowart at rescomp.berkeley.edu>
   
   Revision  Changes    Path
   1.106     +2 -6      ports/net-mgmt/net-snmp4/Makefile
   1.1       +26 -0     ports/net-mgmt/net-snmp4/files/snmpd.in (new)
   1.2       +0 -20     ports/net-mgmt/net-snmp4/files/snmpd.sh.sample (dead)
   1.24      +0 -1      ports/net-mgmt/net-snmp4/pkg-plist
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
