From root@gonefishing.org Sat Feb 20 00:54:17 1999
Return-Path: <root@gonefishing.org>
Received: from sturgeon.gonefishing.org (sturgeon.gonefishing.org [129.121.2.4])
	by hub.freebsd.org (Postfix) with SMTP id 3F98C1132A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 20 Feb 1999 00:54:15 -0800 (PST)
	(envelope-from root@gonefishing.org)
Received: (qmail 28211 invoked by uid 0); 20 Feb 1999 08:54:16 -0000
Message-Id: <19990220085416.28210.qmail@sturgeon.gonefishing.org>
Date: 20 Feb 1999 08:54:16 -0000
From: monte@gonefishing.org
Sender: root@gonefishing.org
Reply-To: monte@gonefishing.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: find -perm <mode> doesn't allow a bitwise-:  on <mode>
X-Send-Pr-Version: 3.2

>Number:         10169
>Category:       bin
>Synopsis:       find -perm <mode> doesn't allow a bitwise-& on <mode>
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    roberto
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 20 01:00:01 PST 1999
>Closed-Date:    Mon Jun 12 03:37:40 PDT 2000
>Last-Modified:  Mon Jun 12 03:38:21 PDT 2000
>Originator:     Monte Mitzelfelt
>Release:        FreeBSD 2.2.6-RELEASE i386
>Organization:
New Mexico Technet, Inc.
>Environment:

	irrelevant

>Description:

	The find -perm option currently supports an exact match,
	or if the mode is preceded by a '-', it checks for a match
	in at least the bits specified on the command line.  It is
	often desirable to find things with any execute or setuid or
	setgid bits set.

>How-To-Repeat:

	irrelevant

>Fix:

	I've included the context diff of a patch that would add in GNU
	find style, a +mode.  Basically, it does a bitwise & of the mask
	against each files mode.  If any bits are set in mask and mode,
	the & sniffs them out and returns a true value.  The man page
	is patched as well.
	
*** old/function.c	Sun Feb  2 11:57:22 1997
--- function.c	Fri Feb 19 10:40:28 1999
***************
*** 741,746 ****
--- 741,748 ----
  	    (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
  	if (plan->flags == F_ATLEAST)
  		return ((plan->m_data | mode) == mode);
+ 	else if (plan->flags == F_ANY )
+ 		return (plan->m_data & mode);
  	else
  		return (mode == plan->m_data);
  	/* NOTREACHED */
***************
*** 759,764 ****
--- 761,771 ----
  
  	if (*perm == '-') {
  		new->flags = F_ATLEAST;
+ 		++perm;
+ 	}
+ 
+ 	if (*perm == '+') {
+ 		new->flags = F_ANY;
  		++perm;
  	}
  
*** old/find.h	Fri Oct  4 06:54:05 1996
--- find.h	Thu Feb 18 00:15:17 1999
***************
*** 58,63 ****
--- 58,64 ----
  #define	F_MTFLAG	1			/* fstype */
  #define	F_MTTYPE	2
  #define	F_ATLEAST	1			/* perm */
+ #define	F_ANY		2			/* perm */
  	int flags;				/* private flags */
  	enum ntype type;			/* plan node type */
  	union {
*** old/find.1	Fri May 22 16:52:16 1998
--- find.1	Thu Feb 18 00:18:39 1999
***************
*** 268,274 ****
  in the comparison.
  If the mode is preceded by a dash (``\-''), this primary evaluates to true
  if at least all of the bits in the mode are set in the file's mode bits.
! If the mode is not preceded by a dash, this primary evaluates to true if
  the bits in the mode exactly match the file's mode bits.
  Note, the first character of a symbolic mode may not be a dash (``\-'').
  .It Ic -print
--- 268,276 ----
  in the comparison.
  If the mode is preceded by a dash (``\-''), this primary evaluates to true
  if at least all of the bits in the mode are set in the file's mode bits.
! If the mode is preceded by a plus (``\+''), this primary evaluates to true
! if any of the bits in the mode are set in the file's mode bits.
! Otherwise, this primary evaluates to true if
  the bits in the mode exactly match the file's mode bits.
  Note, the first character of a symbolic mode may not be a dash (``\-'').
  .It Ic -print

>Release-Note:
>Audit-Trail:

From: "Monte Mitzelfelt" <monte@gonefishing.org>
To: gnats-admin@freebsd.org, freebsd-bugs@freebsd.org
Cc:  
Subject: Re: bin/10169: find -perm <mode> doesn't allow a bitwise-&
Date: Sat, 20 Feb 1999 11:13:14 PST

 On Sat, 20 Feb 1999 gnats-admin@FreeBSD.org wrote:
 
 > Thank you very much for your problem report.
 > It has the internal identification `bin/10169'.
 > The individual assigned to look at your
 > report is: freebsd-bugs. 
 > 
 > >Category:       bin
 > >Responsible:    freebsd-bugs
 > >Synopsis:       find -perm <mode> doesn't allow a bitwise-& on <mode>
 > >Arrival-Date:   Sat Feb 20 01:00:01 PST 1999
 > 
 
 I'm including a fixed version of my patch.
 
 *** old/find.h	Fri Oct  4 06:54:05 1996
 --- find.h	Thu Feb 18 00:15:17 1999
 ***************
 *** 58,63 ****
 --- 58,64 ----
   #define	F_MTFLAG	1			/* fstype */
   #define	F_MTTYPE	2
   #define	F_ATLEAST	1			/* perm */
 + #define	F_ANY		2			/* perm */
   	int flags;				/* private flags */
   	enum ntype type;			/* plan node type */
   	union {
 *** old/find.1	Fri May 22 16:52:16 1998
 --- find.1	Thu Feb 18 00:18:39 1999
 ***************
 *** 268,274 ****
   in the comparison.
   If the mode is preceded by a dash (``\-''), this primary evaluates to true
   if at least all of the bits in the mode are set in the file's mode bits.
 ! If the mode is not preceded by a dash, this primary evaluates to true if
   the bits in the mode exactly match the file's mode bits.
   Note, the first character of a symbolic mode may not be a dash (``\-'').
   .It Ic -print
 --- 268,276 ----
   in the comparison.
   If the mode is preceded by a dash (``\-''), this primary evaluates to true
   if at least all of the bits in the mode are set in the file's mode bits.
 ! If the mode is preceded by a plus (``\+''), this primary evaluates to true
 ! if any of the bits in the mode are set in the file's mode bits.
 ! Otherwise, this primary evaluates to true if
   the bits in the mode exactly match the file's mode bits.
   Note, the first character of a symbolic mode may not be a dash (``\-'').
   .It Ic -print
 *** old/function.c	Sun Feb  2 11:57:22 1997
 --- function.c	Sat Feb 20 12:06:31 1999
 ***************
 *** 741,746 ****
 --- 741,748 ----
   	    (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
   	if (plan->flags == F_ATLEAST)
   		return ((plan->m_data | mode) == mode);
 + 	else if (plan->flags == F_ANY )
 + 		return (plan->m_data & mode);
   	else
   		return (mode == plan->m_data);
   	/* NOTREACHED */
 ***************
 *** 759,764 ****
 --- 761,769 ----
   
   	if (*perm == '-') {
   		new->flags = F_ATLEAST;
 + 		++perm;
 + 	} else if (*perm == '+') {
 + 		new->flags = F_ANY;
   		++perm;
   	}
   
 
 
 
 
 To Unsubscribe: send mail to majordomo@FreeBSD.org
 with "unsubscribe freebsd-bugs" in the body of the message
 
Responsible-Changed-From-To: freebsd-bugs->roberto 
Responsible-Changed-By: nrahlstr 
Responsible-Changed-When: Mon Jun 5 21:54:45 PDT 2000 
Responsible-Changed-Why:  
Ollivier has kindly agreed to look over find(1) related PR's. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=10169 
State-Changed-From-To: open->closed 
State-Changed-By: roberto 
State-Changed-When: Mon Jun 12 03:37:40 PDT 2000 
State-Changed-Why:  
Modified patch applied, thanks! 

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