From andre.albsmeier@siemens.com  Thu Sep  9 07:39:57 2004
Return-Path: <andre.albsmeier@siemens.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id EE2BE16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Sep 2004 07:39:57 +0000 (GMT)
Received: from goliath.siemens.de (goliath.siemens.de [192.35.17.28])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 3D96443D2F
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Sep 2004 07:39:57 +0000 (GMT)
	(envelope-from andre.albsmeier@siemens.com)
Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14])
	by goliath.siemens.de (8.12.6/8.12.6) with ESMTP id i897dtec005828
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 9 Sep 2004 09:39:55 +0200
Received: from mars.cert.siemens.com (mars.cert.siemens.com [139.25.19.9])
	by mail1.siemens.de (8.12.6/8.12.6) with ESMTP id i897dtW1003931
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 9 Sep 2004 09:39:55 +0200
Received: from curry.mchp.siemens.de (curry.mchp.siemens.de [139.25.42.7])
	by mars.cert.siemens.com (8.13.1/8.13.1/$SiemensCERT: mail/cert.mc.pre,v 1.62 2004/08/23 18:38:16 mailadm Exp $) with ESMTP id i897dtva087231
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 9 Sep 2004 09:39:55 +0200 (CEST)
Received: (from localhost)
	by curry.mchp.siemens.de (8.13.1/8.13.1) id i897doqB094112
	for FreeBSD-gnats-submit@freebsd.org; Thu, 9 Sep 2004 09:39:50 +0200 (CEST)
Message-Id: <200409090739.i897dox6008632@curry.mchp.siemens.de>
Date: Thu, 9 Sep 2004 09:39:50 +0200 (CEST)
From: Andre Albsmeier <andre.albsmeier@siemens.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] allow -user/group +/-id constructs in find(1)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         71513
>Category:       bin
>Synopsis:       [PATCH] allow -user/group +/-id constructs in find(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 09 07:40:18 GMT 2004
>Closed-Date:    Thu Jun 01 20:05:46 GMT 2006
>Last-Modified:  Thu Jun 01 20:05:46 GMT 2006
>Originator:     Andre Albsmeier
>Release:        FreeBSD 4.10-STABLE i386
>Organization:
>Environment:

System:

	FreeBSD 4.10-STABLE #0: Thu Aug 5 12:18:13 CEST 2004

>Description:

	find(1) currently doesn't allow the use of -user (-group)
	primaries with numeric arguments and +/- prefixes.

>How-To-Repeat:

	find . -user +999

>Fix:

	The patch below adds this feature. As a side effect, it
	enhances the detection of invalid numerical arguments:
	Before, the command
	
	find . -user 0bla1

	found all files belonging to root. This is now honoured
	with an error message. However, the existing logic to
	detect args which obviously should have been usernames
	was adjusted so commands like

	find . -user bla

	still spit out the "no such user" message as they did
	before (if bla doesn't exist, of course).


--- usr.bin/find/function.c.ORI	Wed Jun 16 19:03:23 2004
+++ usr.bin/find/function.c	Thu Sep  9 09:00:55 2004
@@ -862,7 +862,7 @@
 	PLAN *plan;
 	FTSENT *entry;
 {
-	return entry->fts_statp->st_gid == plan->g_data;
+	COMPARE(entry->fts_statp->st_gid, plan->g_data);
 }
 
 PLAN *
@@ -878,15 +878,19 @@
 	gname = nextarg(option, argvp);
 	ftsoptions &= ~FTS_NOSTAT;
 
+	new = palloc(option);
 	g = getgrnam(gname);
 	if (g == NULL) {
+		char* cp = gname;
+		if( gname[0] == '-' || gname[0] == '+' )
+			gname++;
 		gid = atoi(gname);
 		if (gid == 0 && gname[0] != '0')
 			errx(1, "%s: %s: no such group", option->name, gname);
+		gid = find_parsenum(new, option->name, cp, NULL);
 	} else
 		gid = g->gr_gid;
 
-	new = palloc(option);
 	new->g_data = gid;
 	return new;
 }
@@ -1435,7 +1439,7 @@
 	PLAN *plan;
 	FTSENT *entry;
 {
-	return entry->fts_statp->st_uid == plan->u_data;
+	COMPARE(entry->fts_statp->st_uid, plan->u_data);
 }
 
 PLAN *
@@ -1451,15 +1455,19 @@
 	username = nextarg(option, argvp);
 	ftsoptions &= ~FTS_NOSTAT;
 
+	new = palloc(option);
 	p = getpwnam(username);
 	if (p == NULL) {
+		char* cp = username;
+		if( username[0] == '-' || username[0] == '+' )
+			username++;
 		uid = atoi(username);
 		if (uid == 0 && username[0] != '0')
 			errx(1, "%s: %s: no such user", option->name, username);
+		uid = find_parsenum(new, option->name, cp, NULL);
 	} else
 		uid = p->pw_uid;
 
-	new = palloc(option);
 	new->u_data = uid;
 	return new;
 }

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: krion 
State-Changed-When: Thu May 25 21:24:19 UTC 2006 
State-Changed-Why:  
Awaits for MFC. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=71513 
State-Changed-From-To: patched->closed 
State-Changed-By: krion 
State-Changed-When: Thu Jun 1 20:05:44 UTC 2006 
State-Changed-Why:  
Committed. Thanks! 

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