--- findutils-4.1.20/find/Makefile.am.orig Mon May 26 20:02:34 2003 +++ findutils-4.1.20/find/Makefile.am Wed Jan 28 15:15:13 2004 @@ -3,8 +3,9 @@ bin_PROGRAMS = find find_SOURCES = find.c fstype.c parser.c pred.c tree.c util.c version.c EXTRA_DIST = defs.h $(man_MANS) +DEFS = @DEFS@ -I. -I$(srcdir) -I.. -DWITH_SELINUX INCLUDES = -I../gnulib/lib -I$(top_srcdir)/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCALEDIR=\"$(localedir)\" -LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ +LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ -lselinux man_MANS = find.1 SUBDIRS = testsuite --- findutils-4.2.11/find/defs.h.orig 2005-01-03 01:06:10.000000000 +0100 +++ findutils-4.2.11/find/defs.h 2005-01-09 18:10:03.183117288 +0100 @@ -126,6 +126,10 @@ #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW) #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX) +#ifdef WITH_SELINUX +#include +#endif /*WITH_SELINUX*/ + #if 1 #include typedef bool boolean; @@ -322,6 +322,9 @@ struct dir_id fileid; /* samefile */ mode_t type; /* type */ FILE *stream; /* ls fls fprint0 */ +#ifdef WITH_SELINUX + security_context_t scontext; /* scontext */ +#endif /*WITH_SELINUX*/ struct format_val printf_vec; /* printf fprintf fprint */ } args; @@ -477,6 +484,10 @@ /* Pointer to the function used to stat files. */ int (*xstat) (const char *name, struct stat *statbuf); + +#ifdef WITH_SELINUX + int (*x_getfilecon) (); +#endif /* WITH_SELINUX */ /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW @@ -511,4 +522,9 @@ # define fchdir(fd) (-1) #endif +#ifdef WITH_SELINUX +boolean pred_scontext PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)); +extern int (*x_getfilecon) (); +#endif /*WITH_SELINUX*/ + #endif --- findutils-4.2.6/find/find.1.orig 2004-11-21 10:52:17.000000000 +0100 +++ findutils-4.2.6/find/find.1 2004-11-21 22:52:25.469719184 +0100 @@ -396,6 +396,9 @@ link to a file of type \fIc\fR; if the \-L option has been given, true if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks the type of the file that \-type does not check. +.IP "\-context \fIscontext\fR" +.IP "\--context \fIscontext\fR" +(SELinux only) File has the security context \fIscontext\fR. .SS ACTIONS .IP "\-delete\fR" @@ -633,6 +636,8 @@ File's type (like in ls -l), U=unknown type (shouldn't happen) .IP %Y File's type (like %y), plus follow symlinks: L=loop, N=nonexistent +.IP %Z +(SELinux only) file's security context. .PP A `%' character followed by any other character is discarded (but the other character is printed). --- findutils-4.2.25/find/find.c.orig 2005-08-30 09:40:03.000000000 +0200 +++ findutils-4.2.25/find/find.c 2005-10-25 23:47:22.594687400 +0200 @@ -272,11 +272,17 @@ { case SYMLINK_ALWAYS_DEREF: /* -L */ options.xstat = optionl_stat; +#ifdef WITH_SELINUX + options.x_getfilecon = getfilecon; +#endif /* WITH_SELINUX */ options.no_leaf_check = true; break; case SYMLINK_NEVER_DEREF: /* -P (default) */ options.xstat = optionp_stat; +#ifdef WITH_SELINUX + options.x_getfilecon = lgetfilecon; +#endif /* WITH_SELINUX */ /* Can't turn no_leaf_check off because the user might have specified * -noleaf anyway */ @@ -284,6 +290,9 @@ case SYMLINK_DEREF_ARGSONLY: /* -H */ options.xstat = optionh_stat; +#ifdef WITH_SELINUX + options.x_getfilecon = getfilecon; +#endif /* WITH_SELINUX */ options.no_leaf_check = true; } @@ -394,6 +403,9 @@ struct predicate *cur_pred; char *predicate_name; /* Name of predicate being parsed. */ int end_of_leading_options = 0; /* First arg after any -H/-L etc. */ +#ifdef WITH_SELINUX + int is_selinux_enabled_flag; +#endif /* WITH_SELINUX */ program_name = argv[0]; const struct parser_table *entry_close, *entry_print, *entry_open; @@ -441,6 +453,9 @@ options.ignore_readdir_race = false; state.exit_status = 0; +#ifdef WITH_SELINUX + is_selinux_enabled_flag = (is_selinux_enabled() > 0); +#endif /* WITH_SELINUX */ #if defined(DEBUG_STAT) options.xstat = debug_stat; @@ -537,6 +552,14 @@ if (strchr ("-!(),", argv[i][0]) == NULL) usage (_("paths must precede expression")); predicate_name = argv[i]; +#ifdef WITH_SELINUX + if (! is_selinux_enabled_flag) { + if ((strncmp(predicate_name,"-context",strlen("-context"))==0) || + (strncmp(predicate_name,"--context",strlen("--context"))==0)) { + error (1, 0,_("Error: invalid predicate %s: the kernel is not SELinux-enabled.\n"),predicate_name); + } + } +#endif parse_entry = find_parser (predicate_name); if (parse_entry == NULL) { --- findutils-4.2.25/find/parser.c.orig 2005-07-31 23:01:54.000000000 +0200 +++ findutils-4.2.25/find/parser.c 2005-10-25 23:58:27.823557240 +0200 @@ -47,6 +47,10 @@ /* We need for isatty(). */ #include +#ifdef WITH_SELINUX +#include +#endif /*WITH_SELINUX*/ + #if ENABLE_NLS # include # define _(Text) gettext (Text) @@ -147,6 +151,9 @@ static boolean parse_warn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_xtype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); static boolean parse_quit PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); +#ifdef WITH_SELINUX +static boolean parse_scontext PARAMS((const struct parser_table*, char *argv[], int *arg_ptr)); +#endif /*WITH_SELINUX*/ @@ -280,6 +287,10 @@ PARSE_TEST_NP ("wholename", wholename), /* GNU, replaces -path */ PARSE_OPTION ("xdev", xdev), PARSE_TEST ("xtype", xtype), /* GNU */ +#ifdef WITH_SELINUX + PARSE_TEST ("context", scontext), /* SELINUX */ + PARSE_TEST ("-context", scontext), /* SELINUX */ +#endif /*WITH_SELINUX*/ #ifdef UNIMPLEMENTED_UNIX /* It's pretty ugly for find to know about archive formats. Plus what it could do with cpio archives is very limited. @@ -803,6 +814,10 @@ -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN\n\ -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N\n\ -used N -user NAME -xtype [bcdpfls]\n")); +#ifdef WITH_SELINUX + puts (_("\ + -context CONTEXT\n")); +#endif /*WITH_SELINUX*/ puts (_("\ actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print \n\ -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit\n\ @@ -1614,6 +1629,30 @@ return insert_num (argv, arg_ptr, entry); } +#ifdef WITH_SELINUX + +static boolean +parse_scontext (const struct parser_table *entry, char **argv, int *arg_ptr) +{ + struct predicate *our_pred; + + if ( (argv == NULL) || (argv[*arg_ptr] == NULL) ) + return( false ); + + our_pred = insert_primary_withpred (entry, pred_scontext); + our_pred->need_stat = our_pred->need_type = false; +#ifdef DEBUG + our_pred->p_name = find_pred_name (pred_scontext); +#endif /*DEBUG*/ + + our_pred->args.scontext = argv[*arg_ptr];; + + (*arg_ptr)++; + return( true ); +} + +#endif /*WITH_SELINUX*/ + static boolean parse_used (const struct parser_table* entry, char **argv, int *arg_ptr) { @@ -1949,7 +1988,11 @@ if (*scan2 == '.') for (scan2++; ISDIGIT (*scan2); scan2++) /* Do nothing. */ ; +#ifdef WITH_SELINUX + if (strchr ("abcdDfFgGhHiklmMnpPstuUyYZ", *scan2)) +#else /* WITH_SELINUX */ if (strchr ("abcdDfFgGhHiklmMnpPstuUyY", *scan2)) +#endif /* WITH_SELINUX */ { segmentp = make_segment (segmentp, format, scan2 - format, (int) *scan2); --- findutils-4.2.11/find/pred.c.orig 2005-01-03 01:15:48.000000000 +0100 +++ findutils-4.2.11/find/pred.c 2005-01-09 18:22:25.204312920 +0100 @@ -30,6 +30,14 @@ #include "filemode.h" #include "wait.h" +#ifdef WITH_SELINUX +#include +#endif /*WITH_SELINUX*/ + +#ifndef FNM_CASEFOLD +#define FNM_CASEFOLD (1<<4) +#endif /*FNM_CASEFOLD*/ + #if ENABLE_NLS # include # define _(Text) gettext (Text) @@ -73,7 +81,6 @@ extern int yesno (); - /* Get or fake the disk device blocksize. Usually defined by sys/param.h (if at all). */ #ifndef DEV_BSIZE @@ -202,6 +209,9 @@ {pred_used, "used "}, {pred_user, "user "}, {pred_xtype, "xtype "}, +#ifdef WITH_SELINUX + {pred_scontext, "context"}, +#endif /*WITH_SELINUX*/ {0, "none "} }; @@ -813,6 +823,26 @@ } break; +#ifdef WITH_SELINUX + case 'Z': /* SELinux security context */ + { + security_context_t scontext; + int rv; + rv = (*options.x_getfilecon)(state.rel_pathname, &scontext); + + if ( rv < 0 ) { + (void) fprintf(stderr, "getfileconf(%s): %s", + pathname, strerror(errno)); + (void) fflush(stderr); + } + else { + segment->text[segment->text_len] = 's'; + (void) fprintf (fp, segment->text, scontext); + freecon(scontext); + } + } + break ; +#endif /* WITH_SELINUX */ } } return (true); @@ -1366,6 +1396,31 @@ */ return (pred_type (pathname, &sbuf, pred_ptr)); } + + +#ifdef WITH_SELINUX + +boolean +pred_scontext (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr) +{ + int rv; + security_context_t scontext; + + rv = (*options.x_getfilecon)(state.rel_pathname, &scontext); + + if ( rv < 0 ) { + (void) fprintf(stderr, "getfilecon(%s): %s\n", pathname, strerror(errno)); + (void) fflush(stderr); + return ( false ); + } + + rv= (strcmp(scontext, pred_ptr->args.scontext) == 0); + freecon(scontext); + return rv; +} + +#endif /*WITH_SELINUX*/ + /* 1) fork to get a child; parent remembers the child pid 2) child execs the command requested --- findutils-4.1.7/find/util.c.selinux 2001-05-20 16:39:37.000000000 -0400 +++ findutils-4.1.7/find/util.c 2003-10-10 13:19:10.869534272 -0400 @@ -65,6 +65,9 @@ last_pred->no_default_print = false; last_pred->need_stat = true; last_pred->args.str = NULL; +#ifdef WITH_SELINUX + last_pred->args.scontext = NULL; +#endif last_pred->pred_next = NULL; last_pred->pred_left = NULL; last_pred->pred_right = NULL; --- findutils-4.2.25/po/pl.po.orig 2005-10-25 23:46:10.482650096 +0200 +++ findutils-4.2.25/po/pl.po 2005-10-26 00:00:02.716131376 +0200 @@ -132,6 +132,11 @@ msgid "paths must precede expression" msgstr "ścieżki muszą poprzedzać wyrażenie" +#: find/find.c:559 +#, c-format +msgid "Error: invalid predicate %s: the kernel is not SELinux-enabled.\n" +msgstr "Błąd: błędne wyrażenie %s: jądro nie ma włączonej obsługi SELinuksa.\n" + #: find/find.c:544 #, c-format msgid "invalid predicate `%s'" @@ -338,6 +343,10 @@ "w przypadku braku dostępu do WWW, wysyłając pocztę elektroniczną pod\n" "adres ." +#: find/parser.c:818 +msgid " -context CONTEXT\n" +msgstr " -context KONTEKST\n" + #: find/parser.c:843 msgid "sanity check of the fnmatch() library function failed." msgstr ""