summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Ouyang <Xin.Ouyang@windriver.com>2012-06-26 14:27:33 +0800
committerXin Ouyang <Xin.Ouyang@windriver.com>2012-06-28 10:42:22 +0800
commit02bcec2d7053aa42d0ae71bb8e3fccd228ff166f (patch)
treefc26486d548c423b4f2e6e4e38df982cfa2f8954
parentb4da06fbdc7cd9f82c1905fdf62508f9ef4eeae3 (diff)
downloadmeta-selinux-02bcec2d7053aa42d0ae71bb8e3fccd228ff166f.tar.gz
findutils: 4.2.31, support selinux
Signed-off-by: Xin Ouyang <Xin.Ouyang@windriver.com>
-rw-r--r--recipes-extended/findutils/findutils-4.2.31/findutils-selinux.patch499
-rw-r--r--recipes-extended/findutils/findutils_4.2.31.bbappend9
2 files changed, 508 insertions, 0 deletions
diff --git a/recipes-extended/findutils/findutils-4.2.31/findutils-selinux.patch b/recipes-extended/findutils/findutils-4.2.31/findutils-selinux.patch
new file mode 100644
index 0000000..73a9747
--- /dev/null
+++ b/recipes-extended/findutils/findutils-4.2.31/findutils-selinux.patch
@@ -0,0 +1,499 @@
1From: Xin Ouyang <Xin.Ouyang@windriver.com>
2Date: Thu, 21 Jun 2012 17:01:39 +0800
3Subject: [PATCH] findutils: support selinux.
4
5Upstream-Status: Inappropriate [configuration]
6
7Signed-off-by: Xin Ouyang <Xin.Ouyang@windriver.com>
8---
9 configure.in | 10 +++++
10 doc/find.texi | 12 +++++++
11 find/Makefile.am | 2 +-
12 find/defs.h | 15 ++++++++-
13 find/find.1 | 4 ++
14 find/find.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
15 find/parser.c | 50 ++++++++++++++++++++++++++--
16 find/pred.c | 53 +++++++++++++++++++++++++++++
17 find/util.c | 3 ++
18 9 files changed, 240 insertions(+), 6 deletions(-)
19
20diff --git a/configure.in b/configure.in
21index 6a20f15..00dd7f8 100644
22--- a/configure.in
23+++ b/configure.in
24@@ -101,6 +101,16 @@ dnl C library, try -lsun.
25 AC_CHECK_FUNC(getpwnam, [],
26 [AC_CHECK_LIB(sun, getpwnam)])
27
28+AC_ARG_WITH([selinux],
29+ AS_HELP_STRING([--without-selinux], [disable SELinux support]),
30+ [:],
31+[AC_CHECK_LIB([selinux], [is_selinux_enabled],
32+ [with_selinux=yes], [with_selinux=no])])
33+if test x$with_selinux != xno; then
34+ AC_DEFINE([WITH_SELINUX], [1], [Define to support SELinux])
35+ AC_SUBST([LIBSELINUX], [-lselinux])
36+fi
37+
38 dnl Checks for header files.
39 AC_HEADER_STDC
40 dnl Assume unistd.h is present - coreutils does too.
41diff --git a/doc/find.texi b/doc/find.texi
42index 5b5f0cf..e1ad433 100644
43--- a/doc/find.texi
44+++ b/doc/find.texi
45@@ -1091,6 +1091,14 @@ will probably be made in early 2006.
46
47 @end deffn
48
49+@deffn Test -context pattern
50+True if file's SELinux context matches the pattern @var{pattern}.
51+The pattern uses shell glob matching.
52+
53+This predicate is supported only on @code{find} versions compiled with
54+SELinux support and only when SELinux is enabled.
55+@end deffn
56+
57 @node Contents
58 @section Contents
59
60@@ -1599,6 +1607,10 @@ semantics, you will see a difference between the mode as printed by
61 @item %M
62 File's permissions (in symbolic form, as for @code{ls}). This
63 directive is supported in findutils 4.2.5 and later.
64+
65+@item %Z
66+File's SELinux context, or empty string if the file has no SELinux context
67+or this version of find does not support SELinux.
68 @end table
69
70 @node Size Directives
71diff --git a/find/Makefile.am b/find/Makefile.am
72index 8e71a32..405955a 100644
73--- a/find/Makefile.am
74+++ b/find/Makefile.am
75@@ -6,7 +6,7 @@ bin_PROGRAMS = find
76 find_SOURCES = find.c fstype.c parser.c pred.c tree.c util.c version.c
77 EXTRA_DIST = defs.h $(man_MANS)
78 INCLUDES = -I../gnulib/lib -I$(top_srcdir)/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCALEDIR=\"$(localedir)\"
79-LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
80+LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ @LIBSELINUX@
81 man_MANS = find.1
82 SUBDIRS = testsuite
83
84diff --git a/find/defs.h b/find/defs.h
85index 9369c9a..8a8cf28 100644
86--- a/find/defs.h
87+++ b/find/defs.h
88@@ -131,6 +131,10 @@ int get_statinfo PARAMS((const char *pathname, const char *name, struct stat *p)
89 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
90 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
91
92+#ifdef WITH_SELINUX
93+#include <selinux/selinux.h>
94+#endif
95+
96 #if 1
97 #include <stdbool.h>
98 typedef bool boolean;
99@@ -320,6 +324,9 @@ struct predicate
100 struct dir_id fileid; /* samefile */
101 mode_t type; /* type */
102 FILE *stream; /* ls fls fprint0 */
103+#ifdef WITH_SELINUX
104+ security_context_t scontext; /* scontext */
105+#endif
106 struct format_val printf_vec; /* printf fprintf fprint */
107 } args;
108
109@@ -481,7 +488,9 @@ boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate
110 boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
111 boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
112 boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
113-
114+#ifdef WITH_SELINUX
115+boolean pred_context PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
116+#endif
117
118
119 int launch PARAMS((const struct buildcmd_control *ctl,
120@@ -570,6 +579,10 @@ struct options
121 * can be changed with the positional option, -regextype.
122 */
123 int regex_options;
124+
125+#ifdef WITH_SELINUX
126+ int (*x_getfilecon) ();
127+#endif
128 };
129 extern struct options options;
130
131diff --git a/find/find.1 b/find/find.1
132index 9be362f..2753d47 100644
133--- a/find/find.1
134+++ b/find/find.1
135@@ -487,6 +487,8 @@ links: if the \-H or \-P option was specified, true if the file is a
136 link to a file of type \fIc\fR; if the \-L option has been given, true
137 if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
138 the type of the file that \-type does not check.
139+.IP "\-context \fIpattern\fR"
140+(SELinux only) Security context of the file matches glob \fIpattern\fR.
141
142 .SS ACTIONS
143 .IP "\-delete\fR"
144@@ -789,6 +791,8 @@ File's numeric user ID.
145 File's type (like in ls \-l), U=unknown type (shouldn't happen)
146 .IP %Y
147 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
148+.IP %Z
149+(SELinux only) file's security context
150 .PP
151 A `%' character followed by any other character is discarded, but the
152 other character is printed (don't rely on this, as further format
153diff --git a/find/find.c b/find/find.c
154index df28db6..6b3a2de 100644
155--- a/find/find.c
156+++ b/find/find.c
157@@ -245,6 +245,92 @@ optionp_stat(const char *name, struct stat *p)
158 return lstat(name, p);
159 }
160
161+#ifdef WITH_SELINUX
162+static int
163+fallback_getfilecon(const char *name, security_context_t *p, int prev_rv)
164+{
165+ /* Our original getfilecon() call failed. Perhaps we can't follow a
166+ * symbolic link. If that might be the problem, lgetfilecon() the link.
167+ * Otherwise, admit defeat.
168+ */
169+ switch (errno)
170+ {
171+ case ENOENT:
172+ case ENOTDIR:
173+#ifdef DEBUG_STAT
174+ fprintf(stderr, "fallback_getfilecon(): getfilecon(%s) failed; falling back on lgetfilecon()\n", name);
175+#endif
176+ return lgetfilecon(name, p);
177+
178+ case EACCES:
179+ case EIO:
180+ case ELOOP:
181+ case ENAMETOOLONG:
182+#ifdef EOVERFLOW
183+ case EOVERFLOW: /* EOVERFLOW is not #defined on UNICOS. */
184+#endif
185+ default:
186+ return prev_rv;
187+ }
188+}
189+
190+/* optionh_getfilecon() implements the getfilecon operation when the
191+ * -H option is in effect.
192+ *
193+ * If the item to be examined is a command-line argument, we follow
194+ * symbolic links. If the getfilecon() call fails on the command-line
195+ * item, we fall back on the properties of the symbolic link.
196+ *
197+ * If the item to be examined is not a command-line argument, we
198+ * examine the link itself.
199+ */
200+int
201+optionh_getfilecon(const char *name, security_context_t *p)
202+{
203+ if (0 == state.curdepth)
204+ {
205+ /* This file is from the command line; deference the link (if it
206+ * is a link).
207+ */
208+ int rv = getfilecon(name, p);
209+ if (0 == rv)
210+ return 0; /* success */
211+ else
212+ return fallback_getfilecon(name, p, rv);
213+ }
214+ else
215+ {
216+ /* Not a file on the command line; do not derefernce the link.
217+ */
218+ return lgetfilecon(name, p);
219+ }
220+}
221+
222+/* optionl_getfilecon() implements the getfilecon operation when the
223+ * -L option is in effect. That option makes us examine the thing the
224+ * symbolic link points to, not the symbolic link itself.
225+ */
226+int
227+optionl_getfilecon(const char *name, security_context_t *p)
228+{
229+ int rv = getfilecon(name, p);
230+ if (0 == rv)
231+ return 0; /* normal case. */
232+ else
233+ return fallback_getfilecon(name, p, rv);
234+}
235+
236+/* optionp_getfilecon() implements the stat operation when the -P
237+ * option is in effect (this is also the default). That option makes
238+ * us examine the symbolic link itself, not the thing it points to.
239+ */
240+int
241+optionp_getfilecon(const char *name, security_context_t *p)
242+{
243+ return lgetfilecon(name, p);
244+}
245+#endif /* WITH_SELINUX */
246+
247 #ifdef DEBUG_STAT
248 static uintmax_t stat_count = 0u;
249
250@@ -272,11 +358,17 @@ set_follow_state(enum SymlinkOption opt)
251 {
252 case SYMLINK_ALWAYS_DEREF: /* -L */
253 options.xstat = optionl_stat;
254+#ifdef WITH_SELINUX
255+ options.x_getfilecon = optionl_getfilecon;
256+#endif
257 options.no_leaf_check = true;
258 break;
259
260 case SYMLINK_NEVER_DEREF: /* -P (default) */
261 options.xstat = optionp_stat;
262+#ifdef WITH_SELINUX
263+ options.x_getfilecon = optionp_getfilecon;
264+#endif
265 /* Can't turn no_leaf_check off because the user might have specified
266 * -noleaf anyway
267 */
268@@ -284,6 +376,9 @@ set_follow_state(enum SymlinkOption opt)
269
270 case SYMLINK_DEREF_ARGSONLY: /* -H */
271 options.xstat = optionh_stat;
272+#ifdef WITH_SELINUX
273+ options.x_getfilecon = optionh_getfilecon;
274+#endif
275 options.no_leaf_check = true;
276 }
277
278@@ -1807,7 +1902,7 @@ complete_pending_execs(struct predicate *p)
279 static void
280 process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char *parent)
281 {
282- int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */
283+ int subdirs_left = 0; /* Number of unexamined subdirs in PATHNAME. */
284 boolean subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */
285 int idx; /* Which entry are we on? */
286 struct stat stat_buf;
287diff --git a/find/parser.c b/find/parser.c
288index fcdb98a..e67e09f 100644
289--- a/find/parser.c
290+++ b/find/parser.c
291@@ -48,6 +48,10 @@
292 /* We need <unistd.h> for isatty(). */
293 #include <unistd.h>
294
295+#ifdef WITH_SELINUX
296+#include <selinux/selinux.h>
297+#endif
298+
299 #if ENABLE_NLS
300 # include <libintl.h>
301 # define _(Text) gettext (Text)
302@@ -148,7 +152,9 @@ static boolean parse_noignore_race PARAMS((const struct parser_table*, char *arg
303 static boolean parse_warn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
304 static boolean parse_xtype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
305 static boolean parse_quit PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
306-
307+#ifdef WITH_SELINUX
308+static boolean parse_context PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
309+#endif
310
311
312 boolean parse_print PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
313@@ -216,6 +222,9 @@ static struct parser_table const parse_table[] =
314 PARSE_TEST ("cmin", cmin), /* GNU */
315 PARSE_TEST ("cnewer", cnewer), /* GNU */
316 PARSE_TEST ("ctime", ctime),
317+#ifdef WITH_SELINUX
318+ PARSE_TEST ("context", context), /* GNU */
319+#endif
320 PARSE_POSOPT ("daystart", daystart), /* GNU */
321 PARSE_ACTION ("delete", delete), /* GNU, Mac OS, FreeBSD */
322 PARSE_OPTION ("d", d), /* Mac OS X, FreeBSD, NetBSD, OpenBSD, but deprecated in favour of -depth */
323@@ -801,8 +810,12 @@ tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N\n\
324 puts (_("\
325 -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN\n\
326 -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N\n\
327- -used N -user NAME -xtype [bcdpfls]\n"));
328+ -used N -user NAME -xtype [bcdpfls]"));
329+#ifdef WITH_SELINUX
330 puts (_("\
331+ -context CONTEXT\n"));
332+#endif
333+ puts (_("\n\
334 actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print \n\
335 -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit\n\
336 -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;\n\
337@@ -1718,6 +1731,10 @@ parse_version (const struct parser_table* entry, char **argv, int *arg_ptr)
338 printf("LEAF_OPTIMISATION ");
339 ++features;
340 #endif
341+#if defined(WITH_SELINUX)
342+ printf("SELINUX ");
343+ ++features;
344+#endif
345 if (0 == features)
346 {
347 /* For the moment, leave this as English in case someone wants
348@@ -1729,6 +1746,32 @@ parse_version (const struct parser_table* entry, char **argv, int *arg_ptr)
349 exit (0);
350 }
351
352+#ifdef WITH_SELINUX
353+static boolean
354+parse_context (const struct parser_table* entry, char **argv, int *arg_ptr)
355+{
356+ struct predicate *our_pred;
357+
358+ if ((argv == NULL) || (argv[*arg_ptr] == NULL))
359+ return false;
360+
361+ if (is_selinux_enabled() <= 0)
362+ {
363+ error (1, 0, _("invalid predicate -context: SELinux is not enabled."));
364+ return false;
365+ }
366+ our_pred = insert_primary (entry);
367+ our_pred->need_stat = false;
368+#ifdef DEBUG
369+ our_pred->p_name = find_pred_name (pred_context);
370+#endif /*DEBUG*/
371+ our_pred->args.scontext = argv[*arg_ptr];
372+
373+ (*arg_ptr)++;
374+ return true;
375+}
376+#endif /* WITH_SELINUX */
377+
378 static boolean
379 parse_xdev (const struct parser_table* entry, char **argv, int *arg_ptr)
380 {
381@@ -1971,7 +2014,7 @@ insert_fprintf (FILE *fp, const struct parser_table *entry, PRED_FUNC func, char
382 if (*scan2 == '.')
383 for (scan2++; ISDIGIT (*scan2); scan2++)
384 /* Do nothing. */ ;
385- if (strchr ("abcdDfFgGhHiklmMnpPstuUyY", *scan2))
386+ if (strchr ("abcdDfFgGhHiklmMnpPstuUyYZ", *scan2))
387 {
388 segmentp = make_segment (segmentp, format, scan2 - format,
389 (int) *scan2);
390@@ -2046,6 +2089,7 @@ make_segment (struct segment **segment, char *format, int len, int kind)
391 case 'u': /* user name */
392 case 'y': /* file type */
393 case 'Y': /* symlink pointed file type */
394+ case 'Z': /* SELinux security context */
395 fprintf_stat_needed = true;
396 /* FALLTHROUGH */
397 case 'f': /* basename of path */
398diff --git a/find/pred.c b/find/pred.c
399index 9ec10a4..1da49dc 100644
400--- a/find/pred.c
401+++ b/find/pred.c
402@@ -38,6 +38,10 @@
403 #include "buildcmd.h"
404 #include "yesno.h"
405
406+#ifdef WITH_SELINUX
407+#include <selinux/selinux.h>
408+#endif /*WITH_SELINUX*/
409+
410 #if ENABLE_NLS
411 # include <libintl.h>
412 # define _(Text) gettext (Text)
413@@ -217,6 +221,9 @@ struct pred_assoc pred_table[] =
414 {pred_used, "used "},
415 {pred_user, "user "},
416 {pred_xtype, "xtype "},
417+#ifdef WITH_SELINUX
418+ {pred_context, "context"},
419+#endif /*WITH_SELINUX*/
420 {0, "none "}
421 };
422
423@@ -905,6 +912,27 @@ pred_fprintf (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
424 mode_to_filetype(stat_buf->st_mode & S_IFMT));
425 }
426 break;
427+ case 'Z': /* SELinux security context */
428+#ifdef WITH_SELINUX
429+ {
430+ security_context_t scontext;
431+ int rv;
432+ rv = (*options.x_getfilecon) (state.rel_pathname, &scontext);
433+
434+ if (rv < 0)
435+ {
436+ fprintf (stderr, "getfilecon(%s): %s", pathname,
437+ strerror(errno));
438+ fflush (stderr);
439+ }
440+ else
441+ {
442+ fprintf (fp, segment->text, scontext);
443+ freecon (scontext);
444+ }
445+ }
446+#endif /* WITH_SELINUX */
447+ break;
448 }
449 }
450 return true;
451@@ -1497,6 +1525,31 @@ pred_xtype (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
452 */
453 return (pred_type (pathname, &sbuf, pred_ptr));
454 }
455+
456+#ifdef WITH_SELINUX
457+
458+boolean
459+pred_context (char *pathname, struct stat *stat_buf,
460+ struct predicate *pred_ptr)
461+{
462+ int rv;
463+ security_context_t scontext;
464+
465+ rv = (*options.x_getfilecon) (state.rel_pathname, &scontext);
466+
467+ if (rv < 0)
468+ {
469+ fprintf (stderr, "getfilecon(%s): %s\n", pathname, strerror(errno));
470+ fflush (stderr);
471+ return false;
472+ }
473+
474+ rv = (fnmatch (pred_ptr->args.scontext, scontext, 0) == 0);
475+ freecon (scontext);
476+ return rv;
477+}
478+
479+#endif /*WITH_SELINUX*/
480
481 /* 1) fork to get a child; parent remembers the child pid
482 2) child execs the command requested
483diff --git a/find/util.c b/find/util.c
484index 97c8687..77bdfa8 100644
485--- a/find/util.c
486+++ b/find/util.c
487@@ -78,6 +78,9 @@ get_new_pred (const struct parser_table *entry)
488 last_pred->need_stat = true;
489 last_pred->need_type = true;
490 last_pred->args.str = NULL;
491+#ifdef WITH_SELINUX
492+ last_pred->args.scontext = NULL;
493+#endif
494 last_pred->pred_next = NULL;
495 last_pred->pred_left = NULL;
496 last_pred->pred_right = NULL;
497--
4981.7.5.4
499
diff --git a/recipes-extended/findutils/findutils_4.2.31.bbappend b/recipes-extended/findutils/findutils_4.2.31.bbappend
new file mode 100644
index 0000000..c44e103
--- /dev/null
+++ b/recipes-extended/findutils/findutils_4.2.31.bbappend
@@ -0,0 +1,9 @@
1PR .= ".1"
2
3FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
4
5SRC_URI += "file://findutils-selinux.patch"
6
7DEPENDS += "${@base_contains('DISTRO_FEATURES', 'selinux', 'libselinux', '', d)}"
8
9EXTRA_OECONF += "${@base_contains('DISTRO_FEATURES', 'selinux', '--with-selinux', '--without-selinux', d)}"