From cperon@staff.seccuris.com  Mon Aug 25 18:16:21 2003
Return-Path: <cperon@staff.seccuris.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 7843C16A4BF
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Aug 2003 18:16:21 -0700 (PDT)
Received: from staff.seccuris.com (staff.seccuris.com [204.112.0.40])
	by mx1.FreeBSD.org (Postfix) with SMTP id 93E9243FE3
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 25 Aug 2003 18:16:20 -0700 (PDT)
	(envelope-from cperon@staff.seccuris.com)
Received: (qmail 58204 invoked by uid 1006); 26 Aug 2003 01:16:19 -0000
Message-Id: <20030826011619.58203.qmail@staff.seccuris.com>
Date: 26 Aug 2003 01:16:19 -0000
From: Chris S.J.Peron <maneo@bsdpro.com>
Reply-To: Chris S.J.Peron <maneo@bsdpro.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] rmuser does not remove IPC mechanisms owned by the user
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         55980
>Category:       bin
>Synopsis:       [patch] rmuser does not remove IPC mechanisms owned by the user
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    schweikh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Aug 25 18:20:09 PDT 2003
>Closed-Date:    Sun Mar 14 04:00:09 PST 2004
>Last-Modified:  Sun Mar 14 04:00:09 PST 2004
>Originator:     Chris S.J. Peron
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD movl 5.1-CURRENT FreeBSD 5.1-CURRENT #14: Mon Aug 25 17:22:40 CDT 2003   modulus@movl:/usr/src/sys/i386/compile/RAID0  i386 

	
>Description:

rmuser cleans up processes and files owned by users, but does not
touch any IPC mechanisms owned by the user.

	
>How-To-Repeat:
N/A
	
>Fix:

--- /usr/sbin/rmuser	Tue Jun 24 22:51:27 2003
+++ /usr/sbin/rmuser2	Thu Aug 14 16:50:08 2003
@@ -145,6 +145,22 @@
 	verbose && echo '.'
 }
 
+# rm_ipc
+#	Removes shared memory segments, semaphores and message queues
+#	owned by user $_user
+#
+rm_ipc() {
+	ipcs -s | awk -v u=$1 '/^s/ { if (u == $5) { print $2 } }' | \
+	xargs -J % -n 1 ipcrm -s %
+
+	ipcs -m | awk -v u=$1 '/^m/ { if (u == $5) { print $2 } }' | \
+	xargs -J % -n 1 ipcrm -m %
+
+	ipcs -q | awk -v u=$1 '/^q/ { if (u == $5) { print $2 } }' | \
+	xargs -J % -n 1 ipcrm -q %
+	! verbose && echo -n " ipc"
+}
+
 # rm_user login
 #	Remove user $login from the system. This subroutine makes use
 #	of the pw(8) command to remove a user from the system. The pw(8)
@@ -338,6 +354,7 @@
 	! verbose && echo -n "Removing user ($_user):"
 	rm_crontab $_user
 	rm_at_jobs $_user
+	rm_ipc $_user
 	kill_procs $_user
 	rm_files $_user
 	rm_mail $_user
>Release-Note:
>Audit-Trail:

From: "Christian S.J. Peron" <maneo@bsdpro.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: bin/55980: [patch] rmuser does not remove IPC mechanisms owned by the user
Date: Fri, 27 Feb 2004 18:01:20 +0000

 My previous patch implements redundant flags when calling xargs.
 I have re-created the patch to be a bit more sane.
 
 
 --- usr.sbin/adduser/rmuser.sh.bak	Fri Feb 27 15:54:13 2004
 +++ usr.sbin/adduser/rmuser.sh	Fri Feb 27 17:41:32 2004
 @@ -145,6 +145,19 @@
  	verbose && echo '.'
  }
  
 +# rm_ipc login
 +#	Remove all IPC mechanisms which are owned by the user.
 +#
 +rm_ipc() {
 +	verbose && echo "Removing IPC mechanisms"
 +	for i in s m q
 +	do
 +		ipcs -$i | grep ^$i | awk -v usr=$1 \
 +			'{ if ($5 == usr) { print $2 } }' | \
 +		xargs -n 1 ipcrm -$i
 +	done
 +}
 +
  # rm_user login
  #	Remove user $login from the system. This subroutine makes use
  #	of the pw(8) command to remove a user from the system. The pw(8)
 @@ -338,6 +351,7 @@
  	! verbose && echo -n "Removing user ($_user):"
  	rm_crontab $_user
  	rm_at_jobs $_user
 +	rm_ipc $_user
  	kill_procs $_user
  	rm_files $_user
  	rm_mail $_user
Responsible-Changed-From-To: freebsd-bugs->schweikh 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Sat Feb 28 04:11:02 PST 2004 
Responsible-Changed-Why:  
I'll have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=55980 
State-Changed-From-To: open->patched 
State-Changed-By: schweikh 
State-Changed-When: Sun Feb 29 01:52:14 PST 2004 
State-Changed-Why:  
Committed a slightly different version to CURRENT. 
Thanks Chris, for paying attention to detail! 
MFC in two weeks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=55980 
State-Changed-From-To: patched->closed 
State-Changed-By: schweikh 
State-Changed-When: Sun Mar 14 03:59:06 PST 2004 
State-Changed-Why:  
No MFC because rmuser is a shell script in CURRENT, but perl in STABLE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=55980 
>Unformatted:
