]> git.pld-linux.org Git - packages/findutils.git/blame - findutils-selinux.patch
- updated for 4.2.11
[packages/findutils.git] / findutils-selinux.patch
CommitLineData
32939b0c
JB
1--- findutils-4.1.20/find/Makefile.am.orig Mon May 26 20:02:34 2003
2+++ findutils-4.1.20/find/Makefile.am Wed Jan 28 15:15:13 2004
3@@ -3,8 +3,9 @@
4 bin_PROGRAMS = find
5 find_SOURCES = find.c fstype.c parser.c pred.c tree.c util.c version.c
6 EXTRA_DIST = defs.h $(man_MANS)
7+DEFS = @DEFS@ -I. -I$(srcdir) -I.. -DWITH_SELINUX
8 INCLUDES = -I../gnulib/lib -I$(top_srcdir)/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCALEDIR=\"$(localedir)\"
9-LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
10+LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ -lselinux
11 man_MANS = find.1
12 SUBDIRS = testsuite
13
1db50576
JB
14--- findutils-4.2.11/find/defs.h.orig 2005-01-03 01:06:10.000000000 +0100
15+++ findutils-4.2.11/find/defs.h 2005-01-09 18:10:03.183117288 +0100
dd23e660 16@@ -126,6 +126,10 @@
32939b0c
JB
17 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
18 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
19
20+#ifdef WITH_SELINUX
21+#include <selinux/selinux.h>
22+#endif /*WITH_SELINUX*/
23+
095a6182
JB
24 #if 1
25 #include <stdbool.h>
26 typedef bool boolean;
1db50576
JB
27@@ -290,6 +294,9 @@
28 struct dir_id fileid; /* samefile */
32939b0c
JB
29 mode_t type; /* type */
30 FILE *stream; /* fprint fprint0 */
31+#ifdef WITH_SELINUX
32+ security_context_t scontext; /* scontext */
33+#endif /*WITH_SELINUX*/
34 struct format_val printf_vec; /* printf fprintf */
35 } args;
36
1db50576
JB
37@@ -477,6 +484,10 @@
38
39 /* Pointer to the function used to stat files. */
40 int (*xstat) (const char *name, struct stat *statbuf);
41+
42+#ifdef WITH_SELINUX
43+ int (*x_getfilecon) ();
44+#endif /* WITH_SELINUX */
45 };
46 extern struct options options;
47
48@@ -511,4 +522,9 @@
49 # define fchdir(fd) (-1)
50 #endif
32939b0c
JB
51
52+#ifdef WITH_SELINUX
53+boolean pred_scontext PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
54+extern int (*x_getfilecon) ();
55+#endif /*WITH_SELINUX*/
56+
dd23e660 57 #endif
dace4399
JB
58--- findutils-4.2.6/find/find.1.orig 2004-11-21 10:52:17.000000000 +0100
59+++ findutils-4.2.6/find/find.1 2004-11-21 22:52:25.469719184 +0100
60@@ -396,6 +396,9 @@
61 link to a file of type \fIc\fR; if the \-L option has been given, true
62 if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
63 the type of the file that \-type does not check.
32939b0c
JB
64+.IP "\-context \fIscontext\fR"
65+.IP "\--context \fIscontext\fR"
66+(SELinux only) File has the security context \fIscontext\fR.
095a6182 67
dace4399 68 .SS ACTIONS
095a6182 69 .IP "\-delete\fR"
dace4399 70@@ -633,6 +636,8 @@
095a6182
JB
71 File's type (like in ls -l), U=unknown type (shouldn't happen)
72 .IP %Y
73 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
32939b0c
JB
74+.IP %Z
75+(SELinux only) file's security context.
76 .PP
77 A `%' character followed by any other character is discarded (but the
78 other character is printed).
1db50576
JB
79--- findutils-4.2.11/find/find.c.orig 2005-01-03 01:10:13.000000000 +0100
80+++ findutils-4.2.11/find/find.c 2005-01-09 18:11:42.808971856 +0100
81@@ -238,11 +238,17 @@
dace4399
JB
82 {
83 case SYMLINK_ALWAYS_DEREF: /* -L */
1db50576 84 options.xstat = optionl_stat;
dace4399 85+#ifdef WITH_SELINUX
1db50576 86+ options.x_getfilecon = getfilecon;
dace4399 87+#endif /* WITH_SELINUX */
1db50576 88 options.no_leaf_check = true;
dace4399
JB
89 break;
90
91 case SYMLINK_NEVER_DEREF: /* -P (default) */
1db50576 92 options.xstat = optionp_stat;
dace4399 93+#ifdef WITH_SELINUX
1db50576 94+ options.x_getfilecon = lgetfilecon;
dace4399 95+#endif /* WITH_SELINUX */
1db50576 96 /* Can't turn no_leaf_check off because the user might have specified
dace4399
JB
97 * -noleaf anyway
98 */
1db50576 99@@ -250,6 +256,9 @@
dace4399
JB
100
101 case SYMLINK_DEREF_ARGSONLY: /* -H */
1db50576 102 options.xstat = optionh_stat;
dace4399 103+#ifdef WITH_SELINUX
1db50576 104+ options.x_getfilecon = getfilecon;
dace4399 105+#endif /* WITH_SELINUX */
1db50576 106 options.no_leaf_check = true;
dace4399 107 }
1db50576
JB
108
109@@ -272,6 +281,9 @@
dace4399
JB
110 struct predicate *cur_pred;
111 char *predicate_name; /* Name of predicate being parsed. */
112 int end_of_leading_options = 0; /* First arg after any -H/-L etc. */
32939b0c 113+#ifdef WITH_SELINUX
dace4399 114+ int is_selinux_enabled_flag;
32939b0c 115+#endif /* WITH_SELINUX */
dace4399 116 program_name = argv[0];
32939b0c 117
dace4399 118 #ifdef HAVE_SETLOCALE
1db50576
JB
119@@ -301,6 +313,9 @@
120 options.ignore_readdir_race = false;
121
122 state.exit_status = 0;
dace4399
JB
123+#ifdef WITH_SELINUX
124+ is_selinux_enabled_flag = (is_selinux_enabled() > 0);
125+#endif /* WITH_SELINUX */
126
127 #if defined(DEBUG_STAT)
1db50576
JB
128 options.xstat = debug_stat;
129@@ -382,6 +397,14 @@
32939b0c
JB
130 if (strchr ("-!(),", argv[i][0]) == NULL)
131 usage (_("paths must precede expression"));
132 predicate_name = argv[i];
133+#ifdef WITH_SELINUX
134+ if (! is_selinux_enabled_flag) {
135+ if ((strncmp(predicate_name,"-context",strlen("-context"))==0) ||
136+ (strncmp(predicate_name,"--context",strlen("--context"))==0)) {
137+ error (1, 0,_("Error: invalid predicate %s: the kernel is not SELinux-enabled.\n"),predicate_name);
138+ }
139+ }
140+#endif
141 parse_function = find_parser (predicate_name);
142 if (parse_function == NULL)
143 /* Command line option not recognized */
1db50576
JB
144--- findutils-4.2.11/find/parser.c.orig 2005-01-03 01:10:27.000000000 +0100
145+++ findutils-4.2.11/find/parser.c 2005-01-09 18:12:19.498394216 +0100
146@@ -28,6 +28,10 @@
147 #include "../gnulib/lib/xalloc.h"
095a6182 148
32939b0c
JB
149
150+#ifdef WITH_SELINUX
151+#include <selinux/selinux.h>
152+#endif /*WITH_SELINUX*/
153+
154 #if ENABLE_NLS
155 # include <libintl.h>
156 # define _(Text) gettext (Text)
1db50576 157@@ -129,6 +133,9 @@
095a6182 158 static boolean parse_warn PARAMS((char *argv[], int *arg_ptr));
32939b0c 159 static boolean parse_xtype PARAMS((char *argv[], int *arg_ptr));
095a6182 160 static boolean parse_quit PARAMS((char *argv[], int *arg_ptr));
32939b0c
JB
161+#ifdef WITH_SELINUX
162+static boolean parse_scontext PARAMS((char *argv[], int *arg_ptr));
163+#endif /*WITH_SELINUX*/
164
165 static boolean insert_regex PARAMS((char *argv[], int *arg_ptr, boolean ignore_case));
166 static boolean insert_type PARAMS((char *argv[], int *arg_ptr, boolean (*which_pred )()));
1db50576 167@@ -254,6 +261,10 @@
095a6182 168 {ARG_TEST, "wholename", parse_wholename}, /* GNU, replaces -path */
1db50576 169 {ARG_OPTION, "xdev", parse_xdev},
095a6182 170 {ARG_TEST, "xtype", parse_xtype}, /* GNU */
32939b0c 171+#ifdef WITH_SELINUX
095a6182
JB
172+ {ARG_TEST, "context", parse_scontext}, /* SELINUX */
173+ {ARG_TEST, "-context", parse_scontext}, /* SELINUX */
32939b0c 174+#endif /*WITH_SELINUX*/
dace4399 175 {0, 0, 0}
32939b0c
JB
176 };
177 \f
1db50576 178@@ -726,6 +737,10 @@
32939b0c 179 -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN\n\
095a6182 180 -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N\n\
1db50576 181 -used N -user NAME -xtype [bcdpfls]\n"));
32939b0c
JB
182+#ifdef WITH_SELINUX
183+ puts (_("\
184+ -context CONTEXT\n"));
185+#endif /*WITH_SELINUX*/
186 puts (_("\
187 actions: -exec COMMAND ; -fprint FILE -fprint0 FILE -fprintf FILE FORMAT\n\
095a6182 188 -fls FILE -ok COMMAND ; -print -print0 -printf FORMAT -prune -ls -delete\n\
1db50576 189@@ -1542,6 +1557,32 @@
32939b0c
JB
190 return true;
191 }
192
193+#ifdef WITH_SELINUX
194+
195+static boolean
196+parse_scontext ( argv, arg_ptr )
197+ char *argv[];
198+ int *arg_ptr;
199+{
200+ struct predicate *our_pred;
201+
202+ if ( (argv == NULL) || (argv[*arg_ptr] == NULL) )
203+ return( false );
204+
205+ our_pred = insert_primary(pred_scontext);
206+ our_pred->need_stat = false;
207+#ifdef DEBUG
208+ our_pred->p_name = find_pred_name (pred_scontext);
209+#endif /*DEBUG*/
210+
211+ our_pred->args.scontext = argv[*arg_ptr];;
212+
213+ (*arg_ptr)++;
214+ return( true );
215+}
216+
217+#endif /*WITH_SELINUX*/
218+
219 static boolean
220 parse_xtype (char **argv, int *arg_ptr)
221 {
1db50576 222@@ -1702,7 +1743,11 @@
32939b0c
JB
223 if (*scan2 == '.')
224 for (scan2++; ISDIGIT (*scan2); scan2++)
225 /* Do nothing. */ ;
32939b0c 226+#ifdef WITH_SELINUX
dace4399 227+ if (strchr ("abcdDfFgGhHiklmMnpPstuUyYZ", *scan2))
32939b0c 228+#else /* WITH_SELINUX */
dace4399 229 if (strchr ("abcdDfFgGhHiklmMnpPstuUyY", *scan2))
32939b0c
JB
230+#endif /* WITH_SELINUX */
231 {
232 segmentp = make_segment (segmentp, format, scan2 - format,
233 (int) *scan2);
1db50576
JB
234--- findutils-4.2.11/find/pred.c.orig 2005-01-03 01:15:48.000000000 +0100
235+++ findutils-4.2.11/find/pred.c 2005-01-09 18:22:25.204312920 +0100
236@@ -30,6 +30,14 @@
237 #include "filemode.h"
32939b0c
JB
238 #include "wait.h"
239
240+#ifdef WITH_SELINUX
241+#include <selinux/selinux.h>
242+#endif /*WITH_SELINUX*/
243+
244+#ifndef FNM_CASEFOLD
245+#define FNM_CASEFOLD (1<<4)
246+#endif /*FNM_CASEFOLD*/
247+
248 #if ENABLE_NLS
249 # include <libintl.h>
250 # define _(Text) gettext (Text)
1db50576 251@@ -73,7 +81,6 @@
32939b0c
JB
252
253 extern int yesno ();
254
255-
256 /* Get or fake the disk device blocksize.
257 Usually defined by sys/param.h (if at all). */
258 #ifndef DEV_BSIZE
1db50576 259@@ -202,6 +209,9 @@
32939b0c
JB
260 {pred_used, "used "},
261 {pred_user, "user "},
262 {pred_xtype, "xtype "},
263+#ifdef WITH_SELINUX
264+ {pred_scontext, "context"},
265+#endif /*WITH_SELINUX*/
266 {0, "none "}
267 };
268
1db50576
JB
269@@ -813,6 +823,26 @@
270
271 }
32939b0c
JB
272 break;
273+#ifdef WITH_SELINUX
274+ case 'Z': /* SELinux security context */
275+ {
276+ security_context_t scontext;
277+ int rv;
1db50576 278+ rv = (*options.x_getfilecon)(state.rel_pathname, &scontext);
32939b0c
JB
279+
280+ if ( rv < 0 ) {
281+ (void) fprintf(stderr, "getfileconf(%s): %s",
282+ pathname, strerror(errno));
283+ (void) fflush(stderr);
284+ }
285+ else {
286+ segment->text[segment->text_len] = 's';
287+ (void) fprintf (fp, segment->text, scontext);
288+ freecon(scontext);
289+ }
290+ }
291+ break ;
292+#endif /* WITH_SELINUX */
293 }
294 }
295 return (true);
1db50576
JB
296@@ -1366,6 +1396,31 @@
297 */
32939b0c
JB
298 return (pred_type (pathname, &sbuf, pred_ptr));
299 }
300+
301+
302+#ifdef WITH_SELINUX
303+
304+boolean
1db50576 305+pred_scontext (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
32939b0c
JB
306+{
307+ int rv;
308+ security_context_t scontext;
309+
1db50576 310+ rv = (*options.x_getfilecon)(state.rel_pathname, &scontext);
32939b0c
JB
311+
312+ if ( rv < 0 ) {
313+ (void) fprintf(stderr, "getfilecon(%s): %s\n", pathname, strerror(errno));
314+ (void) fflush(stderr);
315+ return ( false );
316+ }
317+
1db50576 318+ rv= (strcmp(scontext, pred_ptr->args.scontext) == 0);
32939b0c
JB
319+ freecon(scontext);
320+ return rv;
321+}
322+
323+#endif /*WITH_SELINUX*/
324+
325 \f
326 /* 1) fork to get a child; parent remembers the child pid
327 2) child execs the command requested
328--- findutils-4.1.7/find/util.c.selinux 2001-05-20 16:39:37.000000000 -0400
329+++ findutils-4.1.7/find/util.c 2003-10-10 13:19:10.869534272 -0400
330@@ -65,6 +65,9 @@
331 last_pred->no_default_print = false;
332 last_pred->need_stat = true;
333 last_pred->args.str = NULL;
334+#ifdef WITH_SELINUX
335+ last_pred->args.scontext = NULL;
336+#endif
337 last_pred->pred_next = NULL;
338 last_pred->pred_left = NULL;
339 last_pred->pred_right = NULL;
dd23e660
JB
340--- findutils-4.2.8/po/pl.po.orig 2004-11-26 00:55:08.041685696 +0100
341+++ findutils-4.2.8/po/pl.po 2004-11-26 01:02:56.090531456 +0100
32939b0c
JB
342@@ -216,6 +216,11 @@
343 msgid "paths must precede expression"
344