1994-05-27 12:33:43 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Cimarron D. Taylor of the University of California, Berkeley.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2000-06-12 11:12:41 +00:00
|
|
|
#if 0
|
|
|
|
static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95";
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2003-06-14 13:00:21 +00:00
|
|
|
|
2002-04-01 22:56:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ucred.h>
|
|
|
|
#include <sys/stat.h>
|
2004-04-03 17:10:04 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/acl.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
2001-01-23 11:16:50 +00:00
|
|
|
#include <dirent.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fnmatch.h>
|
|
|
|
#include <fts.h>
|
|
|
|
#include <grp.h>
|
2002-06-02 12:57:41 +00:00
|
|
|
#include <limits.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <pwd.h>
|
2001-02-23 16:20:55 +00:00
|
|
|
#include <regex.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2004-05-28 17:17:15 +00:00
|
|
|
#include <ctype.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "find.h"
|
|
|
|
|
2002-03-20 10:32:05 +00:00
|
|
|
static PLAN *palloc(OPTION *);
|
|
|
|
static long long find_parsenum(PLAN *, const char *, char *, char *);
|
|
|
|
static long long find_parsetime(PLAN *, const char *, char *);
|
|
|
|
static char *nextarg(OPTION *, char ***);
|
2001-05-03 18:05:35 +00:00
|
|
|
|
2002-07-13 08:08:46 +00:00
|
|
|
extern char **environ;
|
|
|
|
|
2006-05-14 20:23:01 +00:00
|
|
|
static PLAN *lastexecplus = NULL;
|
|
|
|
|
2001-09-14 12:47:13 +00:00
|
|
|
#define COMPARE(a, b) do { \
|
2001-05-03 18:05:35 +00:00
|
|
|
switch (plan->flags & F_ELG_MASK) { \
|
1994-05-27 12:33:43 +00:00
|
|
|
case F_EQUAL: \
|
|
|
|
return (a == b); \
|
|
|
|
case F_LESSTHAN: \
|
|
|
|
return (a < b); \
|
|
|
|
case F_GREATER: \
|
|
|
|
return (a > b); \
|
|
|
|
default: \
|
|
|
|
abort(); \
|
|
|
|
} \
|
2001-09-14 12:47:13 +00:00
|
|
|
} while(0)
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
static PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
palloc(OPTION *option)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
PLAN *new;
|
|
|
|
|
|
|
|
if ((new = malloc(sizeof(PLAN))) == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
new->execute = option->execute;
|
|
|
|
new->flags = option->flags;
|
|
|
|
new->next = NULL;
|
|
|
|
return new;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* find_parsenum --
|
|
|
|
* Parse a string of the form [+-]# and return the value.
|
|
|
|
*/
|
1996-04-07 12:58:13 +00:00
|
|
|
static long long
|
2003-06-14 13:00:21 +00:00
|
|
|
find_parsenum(PLAN *plan, const char *option, char *vp, char *endch)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1996-04-07 12:58:13 +00:00
|
|
|
long long value;
|
1994-05-27 12:33:43 +00:00
|
|
|
char *endchar, *str; /* Pointer to character ending conversion. */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* Determine comparison from leading + or -. */
|
|
|
|
str = vp;
|
|
|
|
switch (*str) {
|
|
|
|
case '+':
|
|
|
|
++str;
|
2001-05-03 18:05:35 +00:00
|
|
|
plan->flags |= F_GREATER;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
++str;
|
2001-05-03 18:05:35 +00:00
|
|
|
plan->flags |= F_LESSTHAN;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-05-03 18:05:35 +00:00
|
|
|
plan->flags |= F_EQUAL;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
1996-04-07 12:58:13 +00:00
|
|
|
* Convert the string with strtoq(). Note, if strtoq() returns zero
|
1994-05-27 12:33:43 +00:00
|
|
|
* and endchar points to the beginning of the string we know we have
|
|
|
|
* a syntax error.
|
|
|
|
*/
|
1996-04-07 12:58:13 +00:00
|
|
|
value = strtoq(str, &endchar, 10);
|
1994-05-27 12:33:43 +00:00
|
|
|
if (value == 0 && endchar == str)
|
|
|
|
errx(1, "%s: %s: illegal numeric value", option, vp);
|
2006-05-27 18:27:41 +00:00
|
|
|
if (endchar[0] && endch == NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
errx(1, "%s: %s: illegal trailing character", option, vp);
|
|
|
|
if (endch)
|
|
|
|
*endch = endchar[0];
|
2001-05-03 18:05:35 +00:00
|
|
|
return value;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2001-09-14 12:47:13 +00:00
|
|
|
/*
|
|
|
|
* find_parsetime --
|
|
|
|
* Parse a string of the form [+-]([0-9]+[smhdw]?)+ and return the value.
|
|
|
|
*/
|
|
|
|
static long long
|
2003-06-14 13:00:21 +00:00
|
|
|
find_parsetime(PLAN *plan, const char *option, char *vp)
|
2001-09-14 12:47:13 +00:00
|
|
|
{
|
|
|
|
long long secs, value;
|
|
|
|
char *str, *unit; /* Pointer to character ending conversion. */
|
|
|
|
|
|
|
|
/* Determine comparison from leading + or -. */
|
|
|
|
str = vp;
|
|
|
|
switch (*str) {
|
|
|
|
case '+':
|
|
|
|
++str;
|
|
|
|
plan->flags |= F_GREATER;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
++str;
|
|
|
|
plan->flags |= F_LESSTHAN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
plan->flags |= F_EQUAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = strtoq(str, &unit, 10);
|
|
|
|
if (value == 0 && unit == str) {
|
|
|
|
errx(1, "%s: %s: illegal time value", option, vp);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
if (*unit == '\0')
|
|
|
|
return value;
|
|
|
|
|
|
|
|
/* Units syntax. */
|
|
|
|
secs = 0;
|
|
|
|
for (;;) {
|
|
|
|
switch(*unit) {
|
|
|
|
case 's': /* seconds */
|
|
|
|
secs += value;
|
|
|
|
break;
|
|
|
|
case 'm': /* minutes */
|
|
|
|
secs += value * 60;
|
|
|
|
break;
|
|
|
|
case 'h': /* hours */
|
|
|
|
secs += value * 3600;
|
|
|
|
break;
|
|
|
|
case 'd': /* days */
|
|
|
|
secs += value * 86400;
|
|
|
|
break;
|
|
|
|
case 'w': /* weeks */
|
|
|
|
secs += value * 604800;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "%s: %s: bad unit '%c'", option, vp, *unit);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
str = unit + 1;
|
|
|
|
if (*str == '\0') /* EOS */
|
|
|
|
break;
|
|
|
|
value = strtoq(str, &unit, 10);
|
|
|
|
if (value == 0 && unit == str) {
|
|
|
|
errx(1, "%s: %s: illegal time value", option, vp);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
if (*unit == '\0') {
|
|
|
|
errx(1, "%s: %s: missing trailing unit", option, vp);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plan->flags |= F_EXACTTIME;
|
|
|
|
return secs;
|
|
|
|
}
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/*
|
|
|
|
* nextarg --
|
|
|
|
* Check that another argument still exists, return a pointer to it,
|
|
|
|
* and increment the argument vector pointer.
|
|
|
|
*/
|
|
|
|
static char *
|
2003-06-14 13:00:21 +00:00
|
|
|
nextarg(OPTION *option, char ***argvp)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
char *arg;
|
|
|
|
|
|
|
|
if ((arg = **argvp) == 0)
|
|
|
|
errx(1, "%s: requires additional arguments", option->name);
|
|
|
|
(*argvp)++;
|
|
|
|
return arg;
|
|
|
|
} /* nextarg() */
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2006-04-03 20:36:37 +00:00
|
|
|
* The value of n for the inode times (atime, birthtime, ctime, mtime) is a
|
|
|
|
* range, i.e. n matches from (n - 1) to n 24 hour periods. This interacts
|
|
|
|
* with -n, such that "-mtime -1" would be less than 0 days, which isn't what
|
|
|
|
* the user wanted. Correct so that -1 is "less than 1".
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2001-05-03 18:05:35 +00:00
|
|
|
#define TIME_CORRECT(p) \
|
|
|
|
if (((p)->flags & F_ELG_MASK) == F_LESSTHAN) \
|
1994-05-27 12:33:43 +00:00
|
|
|
++((p)->t_data);
|
|
|
|
|
1997-10-13 21:06:22 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* -[acm]min n functions --
|
1997-10-13 21:06:22 +00:00
|
|
|
*
|
2001-05-03 18:05:35 +00:00
|
|
|
* True if the difference between the
|
|
|
|
* file access time (-amin)
|
2006-04-03 20:36:37 +00:00
|
|
|
* file birth time (-Bmin)
|
2001-05-03 18:05:35 +00:00
|
|
|
* last change of file status information (-cmin)
|
|
|
|
* file modification time (-mmin)
|
|
|
|
* and the current time is n min periods.
|
1997-10-13 21:06:22 +00:00
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_Xmin(PLAN *plan, FTSENT *entry)
|
1997-10-13 21:06:22 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
if (plan->flags & F_TIME_C) {
|
|
|
|
COMPARE((now - entry->fts_statp->st_ctime +
|
|
|
|
60 - 1) / 60, plan->t_data);
|
|
|
|
} else if (plan->flags & F_TIME_A) {
|
|
|
|
COMPARE((now - entry->fts_statp->st_atime +
|
|
|
|
60 - 1) / 60, plan->t_data);
|
2006-04-03 20:36:37 +00:00
|
|
|
} else if (plan->flags & F_TIME_B) {
|
|
|
|
COMPARE((now - entry->fts_statp->st_birthtime +
|
|
|
|
60 - 1) / 60, plan->t_data);
|
2001-05-03 18:05:35 +00:00
|
|
|
} else {
|
|
|
|
COMPARE((now - entry->fts_statp->st_mtime +
|
|
|
|
60 - 1) / 60, plan->t_data);
|
|
|
|
}
|
1997-10-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_Xmin(OPTION *option, char ***argvp)
|
1997-10-13 21:06:22 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *nmins;
|
1997-10-13 21:06:22 +00:00
|
|
|
PLAN *new;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
nmins = nextarg(option, argvp);
|
1997-10-13 21:06:22 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
|
|
|
new->t_data = find_parsenum(new, option->name, nmins, NULL);
|
|
|
|
TIME_CORRECT(new);
|
|
|
|
return new;
|
1997-10-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* -[acm]time n functions --
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
2001-05-03 18:05:35 +00:00
|
|
|
* True if the difference between the
|
|
|
|
* file access time (-atime)
|
2006-04-03 20:36:37 +00:00
|
|
|
* file birth time (-Btime)
|
2001-05-03 18:05:35 +00:00
|
|
|
* last change of file status information (-ctime)
|
|
|
|
* file modification time (-mtime)
|
|
|
|
* and the current time is n 24 hour periods.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2001-05-03 18:05:35 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_Xtime(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-09-14 13:42:26 +00:00
|
|
|
time_t xtime;
|
2001-09-14 12:47:13 +00:00
|
|
|
|
2001-09-14 13:42:26 +00:00
|
|
|
if (plan->flags & F_TIME_A)
|
|
|
|
xtime = entry->fts_statp->st_atime;
|
2006-04-03 20:36:37 +00:00
|
|
|
else if (plan->flags & F_TIME_B)
|
|
|
|
xtime = entry->fts_statp->st_birthtime;
|
2001-09-14 13:42:26 +00:00
|
|
|
else if (plan->flags & F_TIME_C)
|
|
|
|
xtime = entry->fts_statp->st_ctime;
|
|
|
|
else
|
|
|
|
xtime = entry->fts_statp->st_mtime;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-09-14 13:42:26 +00:00
|
|
|
if (plan->flags & F_EXACTTIME)
|
|
|
|
COMPARE(now - xtime, plan->t_data);
|
|
|
|
else
|
|
|
|
COMPARE((now - xtime + 86400 - 1) / 86400, plan->t_data);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_Xtime(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-09-14 12:47:13 +00:00
|
|
|
char *value;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
|
2001-09-14 12:47:13 +00:00
|
|
|
value = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
2001-09-14 12:47:13 +00:00
|
|
|
new->t_data = find_parsetime(new, option->name, value);
|
|
|
|
if (!(new->flags & F_EXACTTIME))
|
|
|
|
TIME_CORRECT(new);
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1997-10-13 21:06:22 +00:00
|
|
|
|
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* -maxdepth/-mindepth n functions --
|
1997-10-13 21:06:22 +00:00
|
|
|
*
|
2001-05-03 18:05:35 +00:00
|
|
|
* Does the same as -prune if the level of the current file is
|
|
|
|
* greater/less than the specified maximum/minimum depth.
|
|
|
|
*
|
|
|
|
* Note that -maxdepth and -mindepth are handled specially in
|
|
|
|
* find_execute() so their f_* functions are set to f_always_true().
|
1997-10-13 21:06:22 +00:00
|
|
|
*/
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_mXXdepth(OPTION *option, char ***argvp)
|
1997-10-13 21:06:22 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *dstr;
|
1997-10-13 21:06:22 +00:00
|
|
|
PLAN *new;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
dstr = nextarg(option, argvp);
|
|
|
|
if (dstr[0] == '-')
|
|
|
|
/* all other errors handled by find_parsenum() */
|
|
|
|
errx(1, "%s: %s: value must be positive", option->name, dstr);
|
1997-10-13 21:06:22 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
|
|
|
if (option->flags & F_MAXDEPTH)
|
|
|
|
maxdepth = find_parsenum(new, option->name, dstr, NULL);
|
|
|
|
else
|
|
|
|
mindepth = find_parsenum(new, option->name, dstr, NULL);
|
|
|
|
return new;
|
1997-10-13 21:06:22 +00:00
|
|
|
}
|
|
|
|
|
2004-04-03 17:10:04 +00:00
|
|
|
/*
|
|
|
|
* -acl function --
|
|
|
|
*
|
|
|
|
* Show files with EXTENDED ACL attributes.
|
|
|
|
*/
|
|
|
|
int
|
2005-01-25 14:07:25 +00:00
|
|
|
f_acl(PLAN *plan __unused, FTSENT *entry)
|
2004-04-03 17:10:04 +00:00
|
|
|
{
|
|
|
|
acl_t facl;
|
2009-09-04 20:01:16 +00:00
|
|
|
acl_type_t acl_type;
|
|
|
|
int acl_supported = 0, ret, trivial;
|
2004-04-03 17:10:04 +00:00
|
|
|
|
|
|
|
if (S_ISLNK(entry->fts_statp->st_mode))
|
|
|
|
return 0;
|
2009-09-04 20:01:16 +00:00
|
|
|
ret = pathconf(entry->fts_accpath, _PC_ACL_NFS4);
|
|
|
|
if (ret > 0) {
|
|
|
|
acl_supported = 1;
|
|
|
|
acl_type = ACL_TYPE_NFS4;
|
|
|
|
} else if (ret < 0 && errno != EINVAL) {
|
|
|
|
warn("%s", entry->fts_accpath);
|
|
|
|
return (0);
|
2004-04-03 17:10:04 +00:00
|
|
|
}
|
2009-09-04 20:01:16 +00:00
|
|
|
if (acl_supported == 0) {
|
|
|
|
ret = pathconf(entry->fts_accpath, _PC_ACL_EXTENDED);
|
|
|
|
if (ret > 0) {
|
|
|
|
acl_supported = 1;
|
|
|
|
acl_type = ACL_TYPE_ACCESS;
|
|
|
|
} else if (ret < 0 && errno != EINVAL) {
|
|
|
|
warn("%s", entry->fts_accpath);
|
|
|
|
return (0);
|
2004-04-03 17:10:04 +00:00
|
|
|
}
|
2009-09-04 20:01:16 +00:00
|
|
|
}
|
|
|
|
if (acl_supported == 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
facl = acl_get_file(entry->fts_accpath, acl_type);
|
|
|
|
if (facl == NULL) {
|
|
|
|
warn("%s", entry->fts_accpath);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
ret = acl_is_trivial_np(facl, &trivial);
|
|
|
|
acl_free(facl);
|
|
|
|
if (ret) {
|
2004-04-03 17:10:04 +00:00
|
|
|
warn("%s", entry->fts_accpath);
|
2009-09-04 20:01:16 +00:00
|
|
|
acl_free(facl);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (trivial)
|
|
|
|
return (0);
|
|
|
|
return (1);
|
2004-04-03 17:10:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
2005-01-25 14:07:25 +00:00
|
|
|
c_acl(OPTION *option, char ***argvp __unused)
|
2004-04-03 17:10:04 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
return (palloc(option));
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* -delete functions --
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
2001-05-03 18:05:35 +00:00
|
|
|
* True always. Makes its best shot and continues on regardless.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_delete(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
/* ignore these from fts */
|
|
|
|
if (strcmp(entry->fts_accpath, ".") == 0 ||
|
|
|
|
strcmp(entry->fts_accpath, "..") == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* sanity check */
|
|
|
|
if (isdepth == 0 || /* depth off */
|
2009-05-19 14:23:54 +00:00
|
|
|
(ftsoptions & FTS_NOSTAT)) /* not stat()ing */
|
2001-05-03 18:05:35 +00:00
|
|
|
errx(1, "-delete: insecure options got turned on");
|
|
|
|
|
2009-05-19 14:23:54 +00:00
|
|
|
if (!(ftsoptions & FTS_PHYSICAL) || /* physical off */
|
|
|
|
(ftsoptions & FTS_LOGICAL)) /* or finally, logical on */
|
|
|
|
errx(1, "-delete: forbidden when symlinks are followed");
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* Potentially unsafe - do not accept relative paths whatsoever */
|
|
|
|
if (strchr(entry->fts_accpath, '/') != NULL)
|
|
|
|
errx(1, "-delete: %s: relative path potentially not safe",
|
|
|
|
entry->fts_accpath);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* Turn off user immutable bits if running as root */
|
|
|
|
if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
|
|
|
|
!(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) &&
|
|
|
|
geteuid() == 0)
|
2009-05-30 10:42:19 +00:00
|
|
|
lchflags(entry->fts_accpath,
|
2001-05-03 18:05:35 +00:00
|
|
|
entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
|
|
|
|
|
|
|
|
/* rmdir directories, unlink everything else */
|
|
|
|
if (S_ISDIR(entry->fts_statp->st_mode)) {
|
|
|
|
if (rmdir(entry->fts_accpath) < 0 && errno != ENOTEMPTY)
|
|
|
|
warn("-delete: rmdir(%s)", entry->fts_path);
|
|
|
|
} else {
|
|
|
|
if (unlink(entry->fts_accpath) < 0)
|
|
|
|
warn("-delete: unlink(%s)", entry->fts_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "succeed" */
|
|
|
|
return 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_delete(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT; /* no optimise */
|
|
|
|
isoutput = 1; /* possible output */
|
|
|
|
isdepth = 1; /* -depth implied */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
1997-10-13 21:06:22 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2004-05-28 17:17:15 +00:00
|
|
|
* always_true --
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
Implement a number of primaries present in GNU find, but not present
in our find.
The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)
Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.
Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)
[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.
[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.
2008-02-23 16:29:04 +00:00
|
|
|
* Always true, used for -maxdepth, -mindepth, -xdev, -follow, and -true
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_always_true(PLAN *plan __unused, FTSENT *entry __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2004-05-28 17:17:15 +00:00
|
|
|
/*
|
|
|
|
* -depth functions --
|
|
|
|
*
|
|
|
|
* With argument: True if the file is at level n.
|
|
|
|
* Without argument: Always true, causes descent of the directory hierarchy
|
|
|
|
* to be done so that all entries in a directory are acted on before the
|
|
|
|
* directory itself.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_depth(PLAN *plan, FTSENT *entry)
|
|
|
|
{
|
|
|
|
if (plan->flags & F_DEPTH)
|
|
|
|
COMPARE(entry->fts_level, plan->d_data);
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2004-05-28 17:17:15 +00:00
|
|
|
c_depth(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2004-05-28 17:17:15 +00:00
|
|
|
PLAN *new;
|
|
|
|
char *str;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-05-28 17:17:15 +00:00
|
|
|
new = palloc(option);
|
|
|
|
|
|
|
|
str = **argvp;
|
|
|
|
if (str && !(new->flags & F_DEPTH)) {
|
|
|
|
/* skip leading + or - */
|
|
|
|
if (*str == '+' || *str == '-')
|
|
|
|
str++;
|
|
|
|
/* skip sign */
|
|
|
|
if (*str == '+' || *str == '-')
|
|
|
|
str++;
|
|
|
|
if (isdigit(*str))
|
|
|
|
new->flags |= F_DEPTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new->flags & F_DEPTH) { /* -depth n */
|
|
|
|
char *ndepth;
|
|
|
|
|
|
|
|
ndepth = nextarg(option, argvp);
|
|
|
|
new->d_data = find_parsenum(new, option->name, ndepth, NULL);
|
|
|
|
} else { /* -d */
|
|
|
|
isdepth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
1997-08-29 23:09:45 +00:00
|
|
|
}
|
|
|
|
|
2001-01-23 11:16:50 +00:00
|
|
|
/*
|
|
|
|
* -empty functions --
|
|
|
|
*
|
|
|
|
* True if the file or directory is empty
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_empty(PLAN *plan __unused, FTSENT *entry)
|
2001-01-23 11:16:50 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
if (S_ISREG(entry->fts_statp->st_mode) &&
|
|
|
|
entry->fts_statp->st_size == 0)
|
|
|
|
return 1;
|
2001-01-23 11:16:50 +00:00
|
|
|
if (S_ISDIR(entry->fts_statp->st_mode)) {
|
|
|
|
struct dirent *dp;
|
|
|
|
int empty;
|
|
|
|
DIR *dir;
|
|
|
|
|
|
|
|
empty = 1;
|
|
|
|
dir = opendir(entry->fts_accpath);
|
|
|
|
if (dir == NULL)
|
|
|
|
err(1, "%s", entry->fts_accpath);
|
|
|
|
for (dp = readdir(dir); dp; dp = readdir(dir))
|
|
|
|
if (dp->d_name[0] != '.' ||
|
|
|
|
(dp->d_name[1] != '\0' &&
|
|
|
|
(dp->d_name[1] != '.' || dp->d_name[2] != '\0'))) {
|
|
|
|
empty = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
closedir(dir);
|
2001-05-03 18:05:35 +00:00
|
|
|
return empty;
|
2001-01-23 11:16:50 +00:00
|
|
|
}
|
2001-05-03 18:05:35 +00:00
|
|
|
return 0;
|
2001-01-23 11:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_empty(OPTION *option, char ***argvp __unused)
|
2001-01-23 11:16:50 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
2001-01-23 11:16:50 +00:00
|
|
|
}
|
|
|
|
|
1997-08-29 23:09:45 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* [-exec | -execdir | -ok] utility [arg ... ] ; functions --
|
1997-08-29 23:09:45 +00:00
|
|
|
*
|
|
|
|
* True if the executed utility returns a zero value as exit status.
|
|
|
|
* The end of the primary expression is delimited by a semicolon. If
|
2001-05-03 18:05:35 +00:00
|
|
|
* "{}" occurs anywhere, it gets replaced by the current pathname,
|
|
|
|
* or, in the case of -execdir, the current basename (filename
|
|
|
|
* without leading directory prefix). For -exec and -ok,
|
|
|
|
* the current directory for the execution of utility is the same as
|
|
|
|
* the current directory when the find utility was started, whereas
|
|
|
|
* for -execdir, it is the directory the file resides in.
|
|
|
|
*
|
|
|
|
* The primary -ok differs from -exec in that it requests affirmation
|
|
|
|
* of the user before executing the utility.
|
1997-08-29 23:09:45 +00:00
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_exec(PLAN *plan, FTSENT *entry)
|
1997-08-29 23:09:45 +00:00
|
|
|
{
|
2002-02-27 17:57:00 +00:00
|
|
|
int cnt;
|
1997-08-29 23:09:45 +00:00
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
char *file;
|
|
|
|
|
2002-06-02 12:57:41 +00:00
|
|
|
if (entry == NULL && plan->flags & F_EXECPLUS) {
|
|
|
|
if (plan->e_ppos == plan->e_pbnum)
|
|
|
|
return (1);
|
|
|
|
plan->e_argv[plan->e_ppos] = NULL;
|
|
|
|
goto doexec;
|
|
|
|
}
|
|
|
|
|
1997-08-29 23:09:45 +00:00
|
|
|
/* XXX - if file/dir ends in '/' this will not work -- can it? */
|
2001-05-03 18:05:35 +00:00
|
|
|
if ((plan->flags & F_EXECDIR) && \
|
|
|
|
(file = strrchr(entry->fts_path, '/')))
|
|
|
|
file++;
|
1997-08-29 23:09:45 +00:00
|
|
|
else
|
2001-05-03 18:05:35 +00:00
|
|
|
file = entry->fts_path;
|
1997-08-29 23:09:45 +00:00
|
|
|
|
2002-06-02 12:57:41 +00:00
|
|
|
if (plan->flags & F_EXECPLUS) {
|
|
|
|
if ((plan->e_argv[plan->e_ppos] = strdup(file)) == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
plan->e_len[plan->e_ppos] = strlen(file);
|
|
|
|
plan->e_psize += plan->e_len[plan->e_ppos];
|
|
|
|
if (++plan->e_ppos < plan->e_pnummax &&
|
|
|
|
plan->e_psize < plan->e_psizemax)
|
|
|
|
return (1);
|
|
|
|
plan->e_argv[plan->e_ppos] = NULL;
|
|
|
|
} else {
|
|
|
|
for (cnt = 0; plan->e_argv[cnt]; ++cnt)
|
|
|
|
if (plan->e_len[cnt])
|
|
|
|
brace_subst(plan->e_orig[cnt],
|
|
|
|
&plan->e_argv[cnt], file,
|
|
|
|
plan->e_len[cnt]);
|
|
|
|
}
|
1997-08-29 23:09:45 +00:00
|
|
|
|
2002-06-02 12:57:41 +00:00
|
|
|
doexec: if ((plan->flags & F_NEEDOK) && !queryuser(plan->e_argv))
|
2001-05-03 18:05:35 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* make sure find output is interspersed correctly with subprocesses */
|
1997-08-29 23:09:45 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
|
1998-10-13 14:52:33 +00:00
|
|
|
switch (pid = fork()) {
|
1997-08-29 23:09:45 +00:00
|
|
|
case -1:
|
|
|
|
err(1, "fork");
|
|
|
|
/* NOTREACHED */
|
|
|
|
case 0:
|
2001-05-03 18:05:35 +00:00
|
|
|
/* change dir back from where we started */
|
|
|
|
if (!(plan->flags & F_EXECDIR) && fchdir(dotfd)) {
|
|
|
|
warn("chdir");
|
|
|
|
_exit(1);
|
|
|
|
}
|
1997-08-29 23:09:45 +00:00
|
|
|
execvp(plan->e_argv[0], plan->e_argv);
|
|
|
|
warn("%s", plan->e_argv[0]);
|
|
|
|
_exit(1);
|
|
|
|
}
|
2002-06-02 12:57:41 +00:00
|
|
|
if (plan->flags & F_EXECPLUS) {
|
|
|
|
while (--plan->e_ppos >= plan->e_pbnum)
|
|
|
|
free(plan->e_argv[plan->e_ppos]);
|
|
|
|
plan->e_ppos = plan->e_pbnum;
|
|
|
|
plan->e_psize = plan->e_pbsize;
|
|
|
|
}
|
1997-08-29 23:09:45 +00:00
|
|
|
pid = waitpid(pid, &status, 0);
|
|
|
|
return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
|
|
|
|
}
|
2001-05-03 18:05:35 +00:00
|
|
|
|
1997-08-29 23:09:45 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* c_exec, c_execdir, c_ok --
|
1997-08-29 23:09:45 +00:00
|
|
|
* build three parallel arrays, one with pointers to the strings passed
|
|
|
|
* on the command line, one with (possibly duplicated) pointers to the
|
|
|
|
* argv array, and one with integer values that are lengths of the
|
|
|
|
* strings, but also flags meaning that the string has to be massaged.
|
|
|
|
*/
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_exec(OPTION *option, char ***argvp)
|
1997-08-29 23:09:45 +00:00
|
|
|
{
|
|
|
|
PLAN *new; /* node returned */
|
2002-06-02 12:57:41 +00:00
|
|
|
long argmax;
|
|
|
|
int cnt, i;
|
2002-07-13 08:08:46 +00:00
|
|
|
char **argv, **ap, **ep, *p;
|
1997-08-29 23:09:45 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* XXX - was in c_execdir, but seems unnecessary!?
|
1997-08-29 23:09:45 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
2001-05-03 18:05:35 +00:00
|
|
|
*/
|
1997-08-29 23:09:45 +00:00
|
|
|
isoutput = 1;
|
2001-05-03 18:05:35 +00:00
|
|
|
|
|
|
|
/* XXX - this is a change from the previous coding */
|
|
|
|
new = palloc(option);
|
1997-08-29 23:09:45 +00:00
|
|
|
|
|
|
|
for (ap = argv = *argvp;; ++ap) {
|
|
|
|
if (!*ap)
|
|
|
|
errx(1,
|
2004-07-29 03:33:55 +00:00
|
|
|
"%s: no terminating \";\" or \"+\"", option->name);
|
1997-08-29 23:09:45 +00:00
|
|
|
if (**ap == ';')
|
|
|
|
break;
|
2002-06-02 12:57:41 +00:00
|
|
|
if (**ap == '+' && ap != argv && strcmp(*(ap - 1), "{}") == 0) {
|
|
|
|
new->flags |= F_EXECPLUS;
|
|
|
|
break;
|
|
|
|
}
|
1997-08-29 23:09:45 +00:00
|
|
|
}
|
|
|
|
|
2002-04-02 07:20:56 +00:00
|
|
|
if (ap == argv)
|
|
|
|
errx(1, "%s: no command specified", option->name);
|
|
|
|
|
1997-08-29 23:09:45 +00:00
|
|
|
cnt = ap - *argvp + 1;
|
2002-06-02 12:57:41 +00:00
|
|
|
if (new->flags & F_EXECPLUS) {
|
|
|
|
new->e_ppos = new->e_pbnum = cnt - 2;
|
|
|
|
if ((argmax = sysconf(_SC_ARG_MAX)) == -1) {
|
|
|
|
warn("sysconf(_SC_ARG_MAX)");
|
|
|
|
argmax = _POSIX_ARG_MAX;
|
|
|
|
}
|
2002-07-13 08:08:46 +00:00
|
|
|
argmax -= 1024;
|
|
|
|
for (ep = environ; *ep != NULL; ep++)
|
|
|
|
argmax -= strlen(*ep) + 1 + sizeof(*ep);
|
|
|
|
argmax -= 1 + sizeof(*ep);
|
|
|
|
new->e_pnummax = argmax / 16;
|
|
|
|
argmax -= sizeof(char *) * new->e_pnummax;
|
|
|
|
if (argmax <= 0)
|
|
|
|
errx(1, "no space for arguments");
|
|
|
|
new->e_psizemax = argmax;
|
2002-06-02 12:57:41 +00:00
|
|
|
new->e_pbsize = 0;
|
|
|
|
cnt += new->e_pnummax + 1;
|
2006-05-14 20:23:01 +00:00
|
|
|
new->e_next = lastexecplus;
|
|
|
|
lastexecplus = new;
|
2002-06-02 12:57:41 +00:00
|
|
|
}
|
2002-05-17 05:11:07 +00:00
|
|
|
if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
if ((new->e_orig = malloc(cnt * sizeof(char *))) == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
if ((new->e_len = malloc(cnt * sizeof(int))) == NULL)
|
|
|
|
err(1, NULL);
|
1997-08-29 23:09:45 +00:00
|
|
|
|
|
|
|
for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
|
|
|
|
new->e_orig[cnt] = *argv;
|
2002-06-02 12:57:41 +00:00
|
|
|
if (new->flags & F_EXECPLUS)
|
|
|
|
new->e_pbsize += strlen(*argv) + 1;
|
1997-08-29 23:09:45 +00:00
|
|
|
for (p = *argv; *p; ++p)
|
2002-06-02 12:57:41 +00:00
|
|
|
if (!(new->flags & F_EXECPLUS) && p[0] == '{' &&
|
|
|
|
p[1] == '}') {
|
2001-07-24 14:12:05 +00:00
|
|
|
if ((new->e_argv[cnt] =
|
2002-05-17 05:11:07 +00:00
|
|
|
malloc(MAXPATHLEN)) == NULL)
|
|
|
|
err(1, NULL);
|
1997-08-29 23:09:45 +00:00
|
|
|
new->e_len[cnt] = MAXPATHLEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!*p) {
|
|
|
|
new->e_argv[cnt] = *argv;
|
|
|
|
new->e_len[cnt] = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-06-02 12:57:41 +00:00
|
|
|
if (new->flags & F_EXECPLUS) {
|
|
|
|
new->e_psize = new->e_pbsize;
|
|
|
|
cnt--;
|
|
|
|
for (i = 0; i < new->e_pnummax; i++) {
|
|
|
|
new->e_argv[cnt] = NULL;
|
|
|
|
new->e_len[cnt] = 0;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
argv = ap;
|
|
|
|
goto done;
|
|
|
|
}
|
1997-08-29 23:09:45 +00:00
|
|
|
new->e_argv[cnt] = new->e_orig[cnt] = NULL;
|
|
|
|
|
2002-06-02 12:57:41 +00:00
|
|
|
done: *argvp = argv + 1;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2006-05-14 20:23:01 +00:00
|
|
|
/* Finish any pending -exec ... {} + functions. */
|
|
|
|
void
|
2009-12-29 22:53:27 +00:00
|
|
|
finish_execplus(void)
|
2006-05-14 20:23:01 +00:00
|
|
|
{
|
|
|
|
PLAN *p;
|
|
|
|
|
|
|
|
p = lastexecplus;
|
|
|
|
while (p != NULL) {
|
|
|
|
(p->execute)(p, NULL);
|
|
|
|
p = p->e_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_flags(PLAN *plan, FTSENT *entry)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
u_long flags;
|
|
|
|
|
2001-09-04 16:09:01 +00:00
|
|
|
flags = entry->fts_statp->st_flags;
|
2001-05-03 18:05:35 +00:00
|
|
|
if (plan->flags & F_ATLEAST)
|
2001-09-04 16:09:01 +00:00
|
|
|
return (flags | plan->fl_flags) == flags &&
|
|
|
|
!(flags & plan->fl_notflags);
|
|
|
|
else if (plan->flags & F_ANY)
|
|
|
|
return (flags & plan->fl_flags) ||
|
|
|
|
(flags | plan->fl_notflags) != flags;
|
2001-05-03 18:05:35 +00:00
|
|
|
else
|
2001-09-04 16:09:01 +00:00
|
|
|
return flags == plan->fl_flags &&
|
|
|
|
!(plan->fl_flags & plan->fl_notflags);
|
2001-05-03 18:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_flags(OPTION *option, char ***argvp)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
char *flags_str;
|
|
|
|
PLAN *new;
|
|
|
|
u_long flags, notflags;
|
|
|
|
|
|
|
|
flags_str = nextarg(option, argvp);
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(option);
|
|
|
|
|
|
|
|
if (*flags_str == '-') {
|
|
|
|
new->flags |= F_ATLEAST;
|
|
|
|
flags_str++;
|
2001-09-04 16:09:01 +00:00
|
|
|
} else if (*flags_str == '+') {
|
|
|
|
new->flags |= F_ANY;
|
|
|
|
flags_str++;
|
2001-05-03 18:05:35 +00:00
|
|
|
}
|
|
|
|
if (strtofflags(&flags_str, &flags, ¬flags) == 1)
|
|
|
|
errx(1, "%s: %s: illegal flags string", option->name, flags_str);
|
|
|
|
|
|
|
|
new->fl_flags = flags;
|
2001-09-04 16:09:01 +00:00
|
|
|
new->fl_notflags = notflags;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -follow functions --
|
|
|
|
*
|
|
|
|
* Always true, causes symbolic links to be followed on a global
|
|
|
|
* basis.
|
|
|
|
*/
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_follow(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_PHYSICAL;
|
|
|
|
ftsoptions |= FTS_LOGICAL;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -fstype functions --
|
|
|
|
*
|
|
|
|
* True if the file is of a certain type.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_fstype(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
static dev_t curdev; /* need a guaranteed illegal dev value */
|
|
|
|
static int first = 1;
|
|
|
|
struct statfs sb;
|
1997-03-27 02:36:26 +00:00
|
|
|
static int val_type, val_flags;
|
2005-08-25 13:44:02 +00:00
|
|
|
char *p, save[2] = {0,0};
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
if ((plan->flags & F_MTMASK) == F_MTUNKNOWN)
|
|
|
|
return 0;
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/* Only check when we cross mount point. */
|
|
|
|
if (first || curdev != entry->fts_statp->st_dev) {
|
|
|
|
curdev = entry->fts_statp->st_dev;
|
|
|
|
|
|
|
|
/*
|
2002-05-16 02:19:14 +00:00
|
|
|
* Statfs follows symlinks; find wants the link's filesystem,
|
1994-05-27 12:33:43 +00:00
|
|
|
* not where it points.
|
|
|
|
*/
|
|
|
|
if (entry->fts_info == FTS_SL ||
|
|
|
|
entry->fts_info == FTS_SLNONE) {
|
|
|
|
if ((p = strrchr(entry->fts_accpath, '/')) != NULL)
|
|
|
|
++p;
|
|
|
|
else
|
|
|
|
p = entry->fts_accpath;
|
|
|
|
save[0] = p[0];
|
|
|
|
p[0] = '.';
|
|
|
|
save[1] = p[1];
|
|
|
|
p[1] = '\0';
|
1995-05-30 06:41:30 +00:00
|
|
|
} else
|
1994-05-27 12:33:43 +00:00
|
|
|
p = NULL;
|
|
|
|
|
|
|
|
if (statfs(entry->fts_accpath, &sb))
|
|
|
|
err(1, "%s", entry->fts_accpath);
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
p[0] = save[0];
|
|
|
|
p[1] = save[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
first = 0;
|
1997-03-11 13:48:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Further tests may need both of these values, so
|
|
|
|
* always copy both of them.
|
|
|
|
*/
|
1997-03-27 02:36:26 +00:00
|
|
|
val_flags = sb.f_flags;
|
|
|
|
val_type = sb.f_type;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-03 18:05:35 +00:00
|
|
|
switch (plan->flags & F_MTMASK) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case F_MTFLAG:
|
2001-05-03 18:05:35 +00:00
|
|
|
return val_flags & plan->mt_data;
|
1994-05-27 12:33:43 +00:00
|
|
|
case F_MTTYPE:
|
2001-05-03 18:05:35 +00:00
|
|
|
return val_type == plan->mt_data;
|
1994-05-27 12:33:43 +00:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_fstype(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *fsname;
|
2002-02-27 17:57:00 +00:00
|
|
|
PLAN *new;
|
- Introduce a new struct xvfsconf, the userland version of struct vfsconf.
- Make getvfsbyname() take a struct xvfsconf *.
- Convert several consumers of getvfsbyname() to use struct xvfsconf.
- Correct the getvfsbyname.3 manpage.
- Create a new vfs.conflist sysctl to dump all the struct xvfsconf in the
kernel, and rewrite getvfsbyname() to use this instead of the weird
existing API.
- Convert some {set,get,end}vfsent() consumers to use the new vfs.conflist
sysctl.
- Convert a vfsload() call in nfsiod.c to kldload() and remove the useless
vfsisloadable() and endvfsent() calls.
- Add a warning printf() in vfs_sysctl() to tell people they are using
an old userland.
After these changes, it's possible to modify struct vfsconf without
breaking the binary compatibility. Please note that these changes don't
break this compatibility either.
When bp will have updated mount_smbfs(8) with the patch I sent him, there
will be no more consumers of the {set,get,end}vfsent(), vfsisloadable()
and vfsload() API, and I will promptly delete it.
2002-08-10 20:19:04 +00:00
|
|
|
struct xvfsconf vfc;
|
2001-05-03 18:05:35 +00:00
|
|
|
|
|
|
|
fsname = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
1997-03-11 13:48:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check first for a filesystem name.
|
|
|
|
*/
|
2001-05-03 18:05:35 +00:00
|
|
|
if (getvfsbyname(fsname, &vfc) == 0) {
|
|
|
|
new->flags |= F_MTTYPE;
|
1997-03-11 13:48:37 +00:00
|
|
|
new->mt_data = vfc.vfc_typenum;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1997-03-11 13:48:37 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
switch (*fsname) {
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'l':
|
2001-05-03 18:05:35 +00:00
|
|
|
if (!strcmp(fsname, "local")) {
|
|
|
|
new->flags |= F_MTFLAG;
|
1994-05-27 12:33:43 +00:00
|
|
|
new->mt_data = MNT_LOCAL;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r':
|
2001-05-03 18:05:35 +00:00
|
|
|
if (!strcmp(fsname, "rdonly")) {
|
|
|
|
new->flags |= F_MTFLAG;
|
1994-05-27 12:33:43 +00:00
|
|
|
new->mt_data = MNT_RDONLY;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-05-03 18:05:35 +00:00
|
|
|
|
2000-07-28 20:02:42 +00:00
|
|
|
/*
|
|
|
|
* We need to make filesystem checks for filesystems
|
|
|
|
* that exists but aren't in the kernel work.
|
|
|
|
*/
|
2001-05-03 18:05:35 +00:00
|
|
|
fprintf(stderr, "Warning: Unknown filesystem type %s\n", fsname);
|
|
|
|
new->flags |= F_MTUNKNOWN;
|
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -group gname functions --
|
|
|
|
*
|
|
|
|
* True if the file belongs to the group gname. If gname is numeric and
|
|
|
|
* an equivalent of the getgrnam() function does not return a valid group
|
|
|
|
* name, gname is taken as a group ID.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_group(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2006-05-25 21:20:43 +00:00
|
|
|
COMPARE(entry->fts_statp->st_gid, plan->g_data);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_group(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *gname;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
struct group *g;
|
|
|
|
gid_t gid;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
gname = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2006-05-25 21:20:43 +00:00
|
|
|
new = palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
g = getgrnam(gname);
|
|
|
|
if (g == NULL) {
|
2006-05-25 21:20:43 +00:00
|
|
|
char* cp = gname;
|
Implement a number of primaries present in GNU find, but not present
in our find.
The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)
Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.
Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)
[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.
[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.
2008-02-23 16:29:04 +00:00
|
|
|
if (gname[0] == '-' || gname[0] == '+')
|
2006-05-25 21:20:43 +00:00
|
|
|
gname++;
|
1994-05-27 12:33:43 +00:00
|
|
|
gid = atoi(gname);
|
|
|
|
if (gid == 0 && gname[0] != '0')
|
2001-05-03 18:05:35 +00:00
|
|
|
errx(1, "%s: %s: no such group", option->name, gname);
|
2006-05-25 21:20:43 +00:00
|
|
|
gid = find_parsenum(new, option->name, cp, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else
|
|
|
|
gid = g->gr_gid;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
new->g_data = gid;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -inum n functions --
|
|
|
|
*
|
|
|
|
* True if the file has inode # n.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_inum(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
COMPARE(entry->fts_statp->st_ino, plan->i_data);
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_inum(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *inum_str;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
inum_str = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
|
|
|
new->i_data = find_parsenum(new, option->name, inum_str, NULL);
|
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
Implement a number of primaries present in GNU find, but not present
in our find.
The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)
Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.
Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)
[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.
[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.
2008-02-23 16:29:04 +00:00
|
|
|
/*
|
|
|
|
* -samefile FN
|
|
|
|
*
|
|
|
|
* True if the file has the same inode (eg hard link) FN
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* f_samefile is just f_inum */
|
|
|
|
PLAN *
|
|
|
|
c_samefile(OPTION *option, char ***argvp)
|
|
|
|
{
|
|
|
|
char *fn;
|
|
|
|
PLAN *new;
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
fn = nextarg(option, argvp);
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
new = palloc(option);
|
|
|
|
if (stat(fn, &sb))
|
|
|
|
err(1, "%s", fn);
|
|
|
|
new->i_data = sb.st_ino;
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -links n functions --
|
|
|
|
*
|
|
|
|
* True if the file has n links.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_links(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
COMPARE(entry->fts_statp->st_nlink, plan->l_data);
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_links(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *nlinks;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
nlinks = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
|
|
|
new->l_data = (nlink_t)find_parsenum(new, option->name, nlinks, NULL);
|
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -ls functions --
|
|
|
|
*
|
|
|
|
* Always true - prints the current entry to stdout in "ls" format.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_ls(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp);
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_ls(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
isoutput = 1;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2000-06-12 11:12:41 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* -name functions --
|
1994-05-27 12:33:43 +00:00
|
|
|
*
|
|
|
|
* True if the basename of the filename being examined
|
|
|
|
* matches pattern using Pattern Matching Notation S3.14
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_name(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2008-02-24 00:01:06 +00:00
|
|
|
char fn[PATH_MAX];
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (plan->flags & F_LINK) {
|
|
|
|
name = fn;
|
|
|
|
if (readlink(entry->fts_path, fn, sizeof(fn)) == -1)
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
name = entry->fts_name;
|
|
|
|
return !fnmatch(plan->c_data, name,
|
2001-05-03 18:05:35 +00:00
|
|
|
plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_name(OPTION *option, char ***argvp)
|
2001-02-23 16:20:55 +00:00
|
|
|
{
|
|
|
|
char *pattern;
|
|
|
|
PLAN *new;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
pattern = nextarg(option, argvp);
|
|
|
|
new = palloc(option);
|
2001-02-23 16:20:55 +00:00
|
|
|
new->c_data = pattern;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
2001-02-23 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -newer file functions --
|
|
|
|
*
|
|
|
|
* True if the current file has been modified more recently
|
|
|
|
* then the modification time of the file named by the pathname
|
|
|
|
* file.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_newer(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
if (plan->flags & F_TIME_C)
|
|
|
|
return entry->fts_statp->st_ctime > plan->t_data;
|
|
|
|
else if (plan->flags & F_TIME_A)
|
|
|
|
return entry->fts_statp->st_atime > plan->t_data;
|
2006-04-03 20:36:37 +00:00
|
|
|
else if (plan->flags & F_TIME_B)
|
|
|
|
return entry->fts_statp->st_birthtime > plan->t_data;
|
2001-05-03 18:05:35 +00:00
|
|
|
else
|
|
|
|
return entry->fts_statp->st_mtime > plan->t_data;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_newer(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *fn_or_tspec;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
struct stat sb;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
fn_or_tspec = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
|
|
|
/* compare against what */
|
|
|
|
if (option->flags & F_TIME2_T) {
|
2010-02-09 21:24:41 +00:00
|
|
|
new->t_data = get_date(fn_or_tspec);
|
2001-05-03 18:05:35 +00:00
|
|
|
if (new->t_data == (time_t) -1)
|
|
|
|
errx(1, "Can't parse date/time: %s", fn_or_tspec);
|
|
|
|
} else {
|
|
|
|
if (stat(fn_or_tspec, &sb))
|
|
|
|
err(1, "%s", fn_or_tspec);
|
|
|
|
if (option->flags & F_TIME2_C)
|
|
|
|
new->t_data = sb.st_ctime;
|
|
|
|
else if (option->flags & F_TIME2_A)
|
|
|
|
new->t_data = sb.st_atime;
|
|
|
|
else
|
|
|
|
new->t_data = sb.st_mtime;
|
|
|
|
}
|
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -nogroup functions --
|
|
|
|
*
|
|
|
|
* True if file belongs to a user ID for which the equivalent
|
|
|
|
* of the getgrnam() 9.2.1 [POSIX.1] function returns NULL.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_nogroup(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return group_from_gid(entry->fts_statp->st_gid, 1) == NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_nogroup(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -nouser functions --
|
|
|
|
*
|
|
|
|
* True if file belongs to a user ID for which the equivalent
|
|
|
|
* of the getpwuid() 9.2.2 [POSIX.1] function returns NULL.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_nouser(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return user_from_uid(entry->fts_statp->st_uid, 1) == NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_nouser(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -path functions --
|
|
|
|
*
|
|
|
|
* True if the path of the filename being examined
|
|
|
|
* matches pattern using Pattern Matching Notation S3.14
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_path(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return !fnmatch(plan->c_data, entry->fts_path,
|
|
|
|
plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0);
|
2001-02-23 16:20:55 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* c_path is the same as c_name */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -perm functions --
|
|
|
|
*
|
|
|
|
* The mode argument is used to represent file mode bits. If it starts
|
|
|
|
* with a leading digit, it's treated as an octal mode, otherwise as a
|
|
|
|
* symbolic mode.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_perm(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
mode_t mode;
|
|
|
|
|
|
|
|
mode = entry->fts_statp->st_mode &
|
|
|
|
(S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO);
|
2001-05-03 18:05:35 +00:00
|
|
|
if (plan->flags & F_ATLEAST)
|
|
|
|
return (plan->m_data | mode) == mode;
|
2001-08-30 13:17:58 +00:00
|
|
|
else if (plan->flags & F_ANY)
|
|
|
|
return (mode & plan->m_data);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
2001-05-03 18:05:35 +00:00
|
|
|
return mode == plan->m_data;
|
1994-05-27 12:33:43 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_perm(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *perm;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
mode_t *set;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
perm = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (*perm == '-') {
|
2001-05-03 18:05:35 +00:00
|
|
|
new->flags |= F_ATLEAST;
|
1994-05-27 12:33:43 +00:00
|
|
|
++perm;
|
2000-06-12 10:36:52 +00:00
|
|
|
} else if (*perm == '+') {
|
2001-05-03 18:05:35 +00:00
|
|
|
new->flags |= F_ANY;
|
2000-06-12 10:36:52 +00:00
|
|
|
++perm;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((set = setmode(perm)) == NULL)
|
2001-05-03 18:05:35 +00:00
|
|
|
errx(1, "%s: %s: illegal mode string", option->name, perm);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
new->m_data = getmode(set, 0);
|
1998-12-16 04:50:46 +00:00
|
|
|
free(set);
|
1999-12-19 15:43:19 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -print functions --
|
|
|
|
*
|
2002-03-26 12:05:35 +00:00
|
|
|
* Always true, causes the current pathname to be written to
|
1994-05-27 12:33:43 +00:00
|
|
|
* standard output.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_print(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
1995-10-16 18:32:35 +00:00
|
|
|
(void)puts(entry->fts_path);
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_print(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
isoutput = 1;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1995-05-09 19:02:06 +00:00
|
|
|
/*
|
|
|
|
* -print0 functions --
|
|
|
|
*
|
2002-03-26 12:05:35 +00:00
|
|
|
* Always true, causes the current pathname to be written to
|
1995-05-09 19:02:06 +00:00
|
|
|
* standard output followed by a NUL character
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_print0(PLAN *plan __unused, FTSENT *entry)
|
1995-05-09 19:02:06 +00:00
|
|
|
{
|
|
|
|
fputs(entry->fts_path, stdout);
|
|
|
|
fputc('\0', stdout);
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
1995-05-09 19:02:06 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* c_print0 is the same as c_print */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -prune functions --
|
|
|
|
*
|
|
|
|
* Prune a portion of the hierarchy.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_prune(PLAN *plan __unused, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
if (fts_set(tree, entry, FTS_SKIP))
|
|
|
|
err(1, "%s", entry->fts_path);
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* c_prune == c_simple */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -regex functions --
|
|
|
|
*
|
|
|
|
* True if the whole path of the file matches pattern using
|
|
|
|
* regular expression.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_regex(PLAN *plan, FTSENT *entry)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
char *str;
|
2002-05-17 05:11:07 +00:00
|
|
|
int len;
|
2001-05-03 18:05:35 +00:00
|
|
|
regex_t *pre;
|
|
|
|
regmatch_t pmatch;
|
|
|
|
int errcode;
|
|
|
|
char errbuf[LINE_MAX];
|
|
|
|
int matched;
|
|
|
|
|
|
|
|
pre = plan->re_data;
|
|
|
|
str = entry->fts_path;
|
|
|
|
len = strlen(str);
|
|
|
|
matched = 0;
|
|
|
|
|
|
|
|
pmatch.rm_so = 0;
|
|
|
|
pmatch.rm_eo = len;
|
|
|
|
|
|
|
|
errcode = regexec(pre, str, 1, &pmatch, REG_STARTEND);
|
|
|
|
|
|
|
|
if (errcode != 0 && errcode != REG_NOMATCH) {
|
|
|
|
regerror(errcode, pre, errbuf, sizeof errbuf);
|
|
|
|
errx(1, "%s: %s",
|
|
|
|
plan->flags & F_IGNCASE ? "-iregex" : "-regex", errbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errcode == 0 && pmatch.rm_so == 0 && pmatch.rm_eo == len)
|
|
|
|
matched = 1;
|
|
|
|
|
|
|
|
return matched;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_regex(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
PLAN *new;
|
|
|
|
char *pattern;
|
|
|
|
regex_t *pre;
|
|
|
|
int errcode;
|
|
|
|
char errbuf[LINE_MAX];
|
|
|
|
|
|
|
|
if ((pre = malloc(sizeof(regex_t))) == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
|
|
|
|
pattern = nextarg(option, argvp);
|
|
|
|
|
|
|
|
if ((errcode = regcomp(pre, pattern,
|
|
|
|
regexp_flags | (option->flags & F_IGNCASE ? REG_ICASE : 0))) != 0) {
|
|
|
|
regerror(errcode, pre, errbuf, sizeof errbuf);
|
|
|
|
errx(1, "%s: %s: %s",
|
|
|
|
option->flags & F_IGNCASE ? "-iregex" : "-regex",
|
|
|
|
pattern, errbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
new = palloc(option);
|
|
|
|
new->re_data = pre;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
Implement a number of primaries present in GNU find, but not present
in our find.
The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)
Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.
Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)
[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.
[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.
2008-02-23 16:29:04 +00:00
|
|
|
/* c_simple covers c_prune, c_openparen, c_closeparen, c_not, c_or, c_true, c_false */
|
2001-05-03 18:05:35 +00:00
|
|
|
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_simple(OPTION *option, char ***argvp __unused)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -size n[c] functions --
|
|
|
|
*
|
|
|
|
* True if the file size in bytes, divided by an implementation defined
|
|
|
|
* value and rounded up to the next integer, is n. If n is followed by
|
2006-05-27 18:27:41 +00:00
|
|
|
* one of c k M G T P, the size is in bytes, kilobytes,
|
|
|
|
* megabytes, gigabytes, terabytes or petabytes respectively.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
#define FIND_SIZE 512
|
|
|
|
static int divsize = 1;
|
|
|
|
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_size(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
off_t size;
|
|
|
|
|
|
|
|
size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) /
|
|
|
|
FIND_SIZE : entry->fts_statp->st_size;
|
|
|
|
COMPARE(size, plan->o_data);
|
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_size(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *size_str;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
char endch;
|
2006-05-27 18:27:41 +00:00
|
|
|
off_t scale;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
size_str = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
endch = 'c';
|
2001-05-03 18:05:35 +00:00
|
|
|
new->o_data = find_parsenum(new, option->name, size_str, &endch);
|
2006-05-27 18:27:41 +00:00
|
|
|
if (endch != '\0') {
|
1994-05-27 12:33:43 +00:00
|
|
|
divsize = 0;
|
2006-05-27 18:27:41 +00:00
|
|
|
|
|
|
|
switch (endch) {
|
|
|
|
case 'c': /* characters */
|
|
|
|
scale = 0x1LL;
|
|
|
|
break;
|
|
|
|
case 'k': /* kilobytes 1<<10 */
|
|
|
|
scale = 0x400LL;
|
|
|
|
break;
|
|
|
|
case 'M': /* megabytes 1<<20 */
|
|
|
|
scale = 0x100000LL;
|
|
|
|
break;
|
|
|
|
case 'G': /* gigabytes 1<<30 */
|
|
|
|
scale = 0x40000000LL;
|
|
|
|
break;
|
|
|
|
case 'T': /* terabytes 1<<40 */
|
|
|
|
scale = 0x1000000000LL;
|
|
|
|
break;
|
|
|
|
case 'P': /* petabytes 1<<50 */
|
|
|
|
scale = 0x4000000000000LL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errx(1, "%s: %s: illegal trailing character",
|
|
|
|
option->name, size_str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (new->o_data > QUAD_MAX / scale)
|
|
|
|
errx(1, "%s: %s: value too large",
|
|
|
|
option->name, size_str);
|
|
|
|
new->o_data *= scale;
|
|
|
|
}
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -type c functions --
|
|
|
|
*
|
1997-03-11 13:48:37 +00:00
|
|
|
* True if the type of the file is c, where c is b, c, d, p, f or w
|
|
|
|
* for block special file, character special file, directory, FIFO,
|
|
|
|
* regular file or whiteout respectively.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_type(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_type(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *typestring;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
mode_t mask;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
typestring = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
|
|
|
switch (typestring[0]) {
|
|
|
|
case 'b':
|
|
|
|
mask = S_IFBLK;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
mask = S_IFCHR;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
mask = S_IFDIR;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
mask = S_IFREG;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
mask = S_IFLNK;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
mask = S_IFIFO;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
mask = S_IFSOCK;
|
|
|
|
break;
|
1997-03-11 13:48:37 +00:00
|
|
|
#ifdef FTS_WHITEOUT
|
|
|
|
case 'w':
|
|
|
|
mask = S_IFWHT;
|
|
|
|
ftsoptions |= FTS_WHITEOUT;
|
|
|
|
break;
|
|
|
|
#endif /* FTS_WHITEOUT */
|
1994-05-27 12:33:43 +00:00
|
|
|
default:
|
2001-05-03 18:05:35 +00:00
|
|
|
errx(1, "%s: %s: unknown type", option->name, typestring);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
new = palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
new->m_data = mask;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
Implement a -delete option to find. The code is extremely paranoid and
goes to a fair degree of trouble to enable something like this to
be safe: cd /tmp && find . -mtime +7 -delete
It removes both files and directories. It does not attempt to remove
immutable files (an earlier version I showed to a few people did a chflags
and tried to blow away even immutable files. Too risky..)
It is thought to be safe because it forces the fts(3) driven descent to
only do "minimal risk" stuff. specifically, -follow is disabled, it does
checking to see that it chdir'ed to the directory it thought it was
going to, it will *not* pass a pathname with a '/' character in it to
unlink(), so it should be totally immune to symlink tree races. If it runs
into something "fishy", it bails out rather than blunder ahead.. It's better
to do that if somebody is trying to compromise security rather than risk
giving them an opportunity. Since the unlink()/rmdir() is being called
from within the current working directory during the tree descent, there
are no fork/exec overheads or races.
As a side effect of this paranoia, you cannot do a
"find /somewhere/dir -delete", as the last argument to rmdir() is
"/somewhere/dir", and the checking won't allow it. Besides, one would use
rm -rf for that case anyway. :-)
Reviewed by: pst (some time ago, but I've removed the immutable file
deletion code that he complained about since he last saw it)
1996-10-04 12:54:07 +00:00
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -user uname functions --
|
|
|
|
*
|
|
|
|
* True if the file belongs to the user uname. If uname is numeric and
|
|
|
|
* an equivalent of the getpwnam() S9.2.2 [POSIX.1] function does not
|
|
|
|
* return a valid user name, uname is taken as a user ID.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_user(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2006-05-25 21:20:43 +00:00
|
|
|
COMPARE(entry->fts_statp->st_uid, plan->u_data);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_user(OPTION *option, char ***argvp)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
char *username;
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *new;
|
|
|
|
struct passwd *p;
|
|
|
|
uid_t uid;
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
username = nextarg(option, argvp);
|
1994-05-27 12:33:43 +00:00
|
|
|
ftsoptions &= ~FTS_NOSTAT;
|
|
|
|
|
2006-05-25 21:20:43 +00:00
|
|
|
new = palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
p = getpwnam(username);
|
|
|
|
if (p == NULL) {
|
2006-05-25 21:20:43 +00:00
|
|
|
char* cp = username;
|
|
|
|
if( username[0] == '-' || username[0] == '+' )
|
|
|
|
username++;
|
1994-05-27 12:33:43 +00:00
|
|
|
uid = atoi(username);
|
|
|
|
if (uid == 0 && username[0] != '0')
|
2001-05-03 18:05:35 +00:00
|
|
|
errx(1, "%s: %s: no such user", option->name, username);
|
2006-05-25 21:20:43 +00:00
|
|
|
uid = find_parsenum(new, option->name, cp, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
} else
|
|
|
|
uid = p->pw_uid;
|
|
|
|
|
|
|
|
new->u_data = uid;
|
2001-05-03 18:05:35 +00:00
|
|
|
return new;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* -xdev functions --
|
|
|
|
*
|
2002-03-26 12:05:35 +00:00
|
|
|
* Always true, causes find not to descend past directories that have a
|
1994-05-27 12:33:43 +00:00
|
|
|
* different device ID (st_dev, see stat() S5.6.2 [POSIX.1])
|
|
|
|
*/
|
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_xdev(OPTION *option, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
ftsoptions |= FTS_XDEV;
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
return palloc(option);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ( expression ) functions --
|
|
|
|
*
|
|
|
|
* True if expression is true.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_expr(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-02-27 17:57:00 +00:00
|
|
|
PLAN *p;
|
|
|
|
int state = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (p = plan->p_data[0];
|
2001-05-03 18:05:35 +00:00
|
|
|
p && (state = (p->execute)(p, entry)); p = p->next);
|
|
|
|
return state;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2001-05-03 18:05:35 +00:00
|
|
|
* f_openparen and f_closeparen nodes are temporary place markers. They are
|
1994-05-27 12:33:43 +00:00
|
|
|
* eliminated during phase 2 of find_formplan() --- the '(' node is converted
|
2001-05-03 18:05:35 +00:00
|
|
|
* to a f_expr node containing the expression and the ')' node is discarded.
|
|
|
|
* The functions themselves are only used as constants.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
2001-05-03 18:05:35 +00:00
|
|
|
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_openparen(PLAN *plan __unused, FTSENT *entry __unused)
|
2001-05-03 18:05:35 +00:00
|
|
|
{
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_closeparen(PLAN *plan __unused, FTSENT *entry __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
abort();
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* c_openparen == c_simple */
|
|
|
|
/* c_closeparen == c_simple */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AND operator. Since AND is implicit, no node is allocated.
|
|
|
|
*/
|
1994-05-27 12:33:43 +00:00
|
|
|
PLAN *
|
2003-06-14 13:00:21 +00:00
|
|
|
c_and(OPTION *option __unused, char ***argvp __unused)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2001-05-03 18:05:35 +00:00
|
|
|
return NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* ! expression functions --
|
|
|
|
*
|
|
|
|
* Negation of a primary; the unary NOT operator.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_not(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-02-27 17:57:00 +00:00
|
|
|
PLAN *p;
|
|
|
|
int state = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (p = plan->p_data[0];
|
2001-05-03 18:05:35 +00:00
|
|
|
p && (state = (p->execute)(p, entry)); p = p->next);
|
|
|
|
return !state;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1995-05-30 06:41:30 +00:00
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* c_not == c_simple */
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* expression -o expression functions --
|
|
|
|
*
|
|
|
|
* Alternation of primaries; the OR operator. The second expression is
|
|
|
|
* not evaluated if the first expression is true.
|
|
|
|
*/
|
|
|
|
int
|
2003-06-14 13:00:21 +00:00
|
|
|
f_or(PLAN *plan, FTSENT *entry)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-02-27 17:57:00 +00:00
|
|
|
PLAN *p;
|
|
|
|
int state = 0;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (p = plan->p_data[0];
|
2001-05-03 18:05:35 +00:00
|
|
|
p && (state = (p->execute)(p, entry)); p = p->next);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (state)
|
2001-05-03 18:05:35 +00:00
|
|
|
return 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
for (p = plan->p_data[1];
|
2001-05-03 18:05:35 +00:00
|
|
|
p && (state = (p->execute)(p, entry)); p = p->next);
|
|
|
|
return state;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 18:05:35 +00:00
|
|
|
/* c_or == c_simple */
|
Implement a number of primaries present in GNU find, but not present
in our find.
The following are nops because they aren't relevant to our find:
-ignore_readdir_race
-noignore_readdir_race
-noleaf
The following aliaes were created:
-gid -> -group [2]
-uid -> -user [2]
-wholename -> -path
-iwholename -> ipath
-mount -> -xdev
-d -> -depth [1]
The following new primaries were created:
-lname like -name, but matches symbolic links only)
-ilname like -lname but case insensitive
-quit exit(0)
-samefile returns true for hard links to the specified file
-true Always true
I changed one primary to match GNU find since I think our use of it violates
POLA
-false Always false (was an alias for -not!)
Also, document the '+' modifier for -execdir, as well as all of the above.
This was previously implemented.
Document the remaining 7 primaries that are in GNU find, but aren't yet
implemented in find(1)
[1] This was done in GNU find for compatibility with FreeBSD, yet they
mixed up command line args and primary args.
[2] -uid/-gid in GNU find ONLY takes a numeric arg, but that arg does the
normal range thing that. GNU find -user and -uid also take a numberic arg,
but don't do the range processing. find(1) does both for -user and -group,
so making -uid and -gid aliases is compatible for all non-error cases used
in GNU find. While not perfect emulation, this seems a reasonable thing
for us.
2008-02-23 16:29:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* -false
|
|
|
|
*
|
|
|
|
* Always false.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_false(PLAN *plan __unused, FTSENT *entry __unused)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* c_false == c_simple */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* -quit
|
|
|
|
*
|
|
|
|
* Exits the program
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
f_quit(PLAN *plan __unused, FTSENT *entry __unused)
|
|
|
|
{
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* c_quit == c_simple */
|