Gentoo Archives: gentoo-commits

From: "Chris PeBenito (pebenito)" <pebenito@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-apps/findutils/files: findutils-4.4.2-selinux.diff
Date: Sun, 09 May 2010 14:17:38
Message-Id: 20100509141733.EB8FB2C459@corvid.gentoo.org
1 pebenito 10/05/09 14:17:33
2
3 Added: findutils-4.4.2-selinux.diff
4 Log:
5 Fix findutils SELinux patch to deal with whitespace changes in findutils 4.4.2. #315759.
6 (Portage version: 2.2_rc67/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 sys-apps/findutils/files/findutils-4.4.2-selinux.diff
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-apps/findutils/files/findutils-4.4.2-selinux.diff?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/sys-apps/findutils/files/findutils-4.4.2-selinux.diff?rev=1.1&content-type=text/plain
13
14 Index: findutils-4.4.2-selinux.diff
15 ===================================================================
16 diff -purN findutils-4.4.2.orig/find/Makefile.am findutils-4.4.2/find/Makefile.am
17 --- findutils-4.4.2.orig/find/Makefile.am 2009-05-16 15:17:01.000000000 +0000
18 +++ findutils-4.4.2/find/Makefile.am 2010-04-25 03:58:33.762402367 +0000
19 @@ -2,6 +2,7 @@ AUTOMAKE_OPTIONS = std-options
20 localedir = $(datadir)/locale
21 # noinst_PROGRAMS = regexprops
22 # regexprops_SOURCES = regexprops.c
23 +DEFS = @DEFS@ -I. -I$(srcdir) -I.. -DWITH_SELINUX
24
25 noinst_LIBRARIES = libfindtools.a
26 libfindtools_a_SOURCES = finddata.c fstype.c parser.c pred.c tree.c util.c
27 @@ -26,7 +27,7 @@ endif
28
29 EXTRA_DIST = defs.h $(man_MANS)
30 INCLUDES = -I../gnulib/lib -I$(top_srcdir)/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCALEDIR=\"$(localedir)\"
31 -LDADD = ./libfindtools.a ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ @LIB_CLOCK_GETTIME@ @FINDLIBS@
32 +LDADD = ./libfindtools.a ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ @LIB_CLOCK_GETTIME@ @FINDLIBS@ -lselinux
33 man_MANS = find.1
34 SUBDIRS = . testsuite
35
36 diff -purN findutils-4.4.2.orig/find/Makefile.in findutils-4.4.2/find/Makefile.in
37 --- findutils-4.4.2.orig/find/Makefile.in 2009-05-16 15:28:13.000000000 +0000
38 +++ findutils-4.4.2/find/Makefile.in 2010-04-25 03:58:33.762402367 +0000
39 @@ -275,7 +275,7 @@ CPP = @CPP@
40 CPPFLAGS = @CPPFLAGS@
41 CYGPATH_W = @CYGPATH_W@
42 DEFAULT_ARG_SIZE = @DEFAULT_ARG_SIZE@
43 -DEFS = @DEFS@
44 +DEFS = @DEFS@ -I. -I$(srcdir) -I.. -DWITH_SELINUX
45 DEPDIR = @DEPDIR@
46 DIRENT_H = @DIRENT_H@
47 ECHO_C = @ECHO_C@
48 @@ -607,7 +607,7 @@ libfindtools_a_SOURCES = finddata.c fsty
49 @WITH_FTS_TRUE@oldfind_SOURCES = find.c
50 @WITH_FTS_FALSE@ftsfind_SOURCES = ftsfind.c
51 EXTRA_DIST = defs.h $(man_MANS)
52 -LDADD = ./libfindtools.a ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ @LIB_CLOCK_GETTIME@ @FINDLIBS@
53 +LDADD = ./libfindtools.a ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@ @LIB_CLOCK_GETTIME@ @FINDLIBS@ -lselinux
54 man_MANS = find.1
55 SUBDIRS = . testsuite
56 all: all-recursive
57 diff -purN findutils-4.4.2.orig/find/defs.h findutils-4.4.2/find/defs.h
58 --- findutils-4.4.2.orig/find/defs.h 2009-05-16 15:17:01.000000000 +0000
59 +++ findutils-4.4.2/find/defs.h 2010-04-25 03:58:33.762402367 +0000
60 @@ -91,6 +91,9 @@ int get_statinfo PARAMS((const char *pat
61 #define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
62 #define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
63
64 +#ifdef WITH_SELINUX
65 +#include <selinux/selinux.h>
66 +#endif /*WITH_SELINUX*/
67
68 struct predicate;
69 struct options;
70 @@ -315,6 +318,9 @@ struct predicate
71 struct samefile_file_id samefileid; /* samefile */
72 mode_t type; /* type */
73 struct format_val printf_vec; /* printf fprintf fprint ls fls print0 fprint0 print */
74 +#ifdef WITH_SELINUX
75 + security_context_t scontext; /* scontext */
76 +#endif /*WITH_SELINUX*/
77 } args;
78
79 /* The next predicate in the user input sequence,
80 @@ -459,7 +465,9 @@ PREDICATEFUNCTION pred_used;
81 PREDICATEFUNCTION pred_user;
82 PREDICATEFUNCTION pred_writable;
83 PREDICATEFUNCTION pred_xtype;
84 -
85 +#ifdef WITH_SELINUX
86 +PREDICATEFUNCTION pred_scontext;
87 +#endif /* WITH_SELINUX */
88
89
90 int launch PARAMS((const struct buildcmd_control *ctl,
91 @@ -605,10 +613,13 @@ struct options
92 */
93 unsigned short optimisation_level;
94
95 -
96 /* How should we quote filenames in error messages and so forth?
97 */
98 enum quoting_style err_quoting_style;
99 +
100 +#ifdef WITH_SELINUX
101 + int (*x_getfilecon)();
102 +#endif /* WITH_SELINUX */
103 };
104 extern struct options options;
105
106 diff -purN findutils-4.4.2.orig/find/find.1 findutils-4.4.2/find/find.1
107 --- findutils-4.4.2.orig/find/find.1 2009-05-16 15:17:01.000000000 +0000
108 +++ findutils-4.4.2/find/find.1 2010-04-25 03:58:33.762402367 +0000
109 @@ -934,6 +934,10 @@ checks the type of the file that
110 .B \-type
111 does not check.
112
113 +.IP "\-context \fIscontext\fR"
114 +.IP "\--context \fIscontext\fR"
115 +(SELinux only) File has the security context \fIscontext\fR.
116 +
117 .SS ACTIONS
118 .IP "\-delete\fR"
119 Delete files; true if removal succeeded. If the removal failed, an
120 @@ -1354,6 +1358,8 @@ File's type (like in
121 U=unknown type (shouldn't happen)
122 .IP %Y
123 File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
124 +.IP %Z
125 +(SELinux only) file's security context.
126 .PP
127 A `%' character followed by any other character is discarded, but the
128 other character is printed (don't rely on this, as further format
129 diff -purN findutils-4.4.2.orig/find/find.c findutils-4.4.2/find/find.c
130 --- findutils-4.4.2.orig/find/find.c 2009-05-16 15:17:01.000000000 +0000
131 +++ findutils-4.4.2/find/find.c 2010-04-25 03:58:33.764899827 +0000
132 @@ -1270,7 +1270,7 @@ process_path (char *pathname, char *name
133 static void
134 process_dir (char *pathname, char *name, int pathlen, const struct stat *statp, char *parent)
135 {
136 - int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */
137 + int subdirs_left=0; /* Number of unexamined subdirs in PATHNAME. */
138 boolean subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */
139 unsigned int idx; /* Which entry are we on? */
140 struct stat stat_buf;
141 diff -purN findutils-4.4.2.orig/find/parser.c findutils-4.4.2/find/parser.c
142 --- findutils-4.4.2.orig/find/parser.c 2009-05-16 15:17:01.000000000 +0000
143 +++ findutils-4.4.2/find/parser.c 2010-04-25 03:58:33.764899827 +0000
144 @@ -53,6 +53,13 @@
145 #include <unistd.h>
146 #include <sys/stat.h>
147
148 +#ifdef WITH_SELINUX
149 +#include <selinux/selinux.h>
150 +int optionh_getfilecon(const char *name, security_context_t *p);
151 +int optionl_getfilecon(const char *name, security_context_t *p);
152 +int optionp_getfilecon(const char *name, security_context_t *p);
153 +#endif /*WITH_SELINUX*/
154 +
155 #if ENABLE_NLS
156 # include <libintl.h>
157 # define _(Text) gettext (Text)
158 @@ -155,6 +162,9 @@ static boolean parse_noignore_race PARAM
159 static boolean parse_warn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
160 static boolean parse_xtype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
161 static boolean parse_quit PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
162 +#ifdef WITH_SELINUX
163 +static boolean parse_scontext PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
164 +#endif /*WITH_SELINUX*/
165
166 boolean parse_print PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
167
168 @@ -340,6 +350,8 @@ static struct parser_table const parse_t
169 {ARG_TEST, "-help", parse_help, NULL}, /* GNU */
170 {ARG_TEST, "version", parse_version, NULL}, /* GNU */
171 {ARG_TEST, "-version", parse_version, NULL}, /* GNU */
172 + {ARG_TEST, "context", parse_scontext, pred_scontext}, /* SELinux */
173 + {ARG_TEST, "-context", parse_scontext, pred_scontext}, /* SELinux */
174 {0, 0, 0, 0}
175 };
176
177 @@ -451,10 +463,16 @@ set_follow_state(enum SymlinkOption opt)
178 case SYMLINK_ALWAYS_DEREF: /* -L */
179 options.xstat = optionl_stat;
180 options.no_leaf_check = true;
181 +#ifdef WITH_SELINUX
182 + options.x_getfilecon = optionl_getfilecon;
183 +#endif /* WITH_SELINUX */
184 break;
185
186 case SYMLINK_NEVER_DEREF: /* -P (default) */
187 options.xstat = optionp_stat;
188 +#ifdef WITH_SELINUX
189 + options.x_getfilecon = optionp_getfilecon;
190 +#endif /* WITH_SELINUX */
191 /* Can't turn no_leaf_check off because the user might have specified
192 * -noleaf anyway
193 */
194 @@ -463,6 +481,9 @@ set_follow_state(enum SymlinkOption opt)
195 case SYMLINK_DEREF_ARGSONLY: /* -H */
196 options.xstat = optionh_stat;
197 options.no_leaf_check = true;
198 +#ifdef WITH_SELINUX
199 + options.x_getfilecon = optionh_getfilecon;
200 +#endif /* WITH_SELINUX */
201 }
202 }
203 options.symlink_handling = opt;
204 @@ -670,6 +691,94 @@ collect_arg_stat_info(char **argv, int *
205
206 The predicate structure is updated with the new information. */
207
208 +#ifdef WITH_SELINUX
209 +
210 +static int
211 +fallback_getfilecon(const char *name, security_context_t *p, int prev_rv)
212 +{
213 + /* Our original getfilecon() call failed. Perhaps we can't follow a
214 + * symbolic link. If that might be the problem, lgetfilecon() the link.
215 + * Otherwise, admit defeat.
216 + */
217 + switch (errno)
218 + {
219 + case ENOENT:
220 + case ENOTDIR:
221 +#ifdef DEBUG_STAT
222 + fprintf(stderr, "fallback_getfilecon(): getfilecon(%s) failed; falling back on lgetfilecon()\n", name);
223 +#endif
224 + return lgetfilecon(name, p);
225 +
226 + case EACCES:
227 + case EIO:
228 + case ELOOP:
229 + case ENAMETOOLONG:
230 +#ifdef EOVERFLOW
231 + case EOVERFLOW: /* EOVERFLOW is not #defined on UNICOS. */
232 +#endif
233 + default:
234 + return prev_rv;
235 + }
236 +}
237 +
238 +
239 +/* optionh_getfilecon() implements the getfilecon operation when the
240 + * -H option is in effect.
241 + *
242 + * If the item to be examined is a command-line argument, we follow
243 + * symbolic links. If the getfilecon() call fails on the command-line
244 + * item, we fall back on the properties of the symbolic link.
245 + *
246 + * If the item to be examined is not a command-line argument, we
247 + * examine the link itself.
248 + */
249 +int
250 +optionh_getfilecon(const char *name, security_context_t *p)
251 +{
252 + if (0 == state.curdepth)
253 + {
254 + /* This file is from the command line; deference the link (if it
255 + * is a link).
256 + */
257 + int rv = getfilecon(name, p);
258 + if (0 == rv)
259 + return 0; /* success */
260 + else
261 + return fallback_getfilecon(name, p, rv);
262 + }
263 + else
264 + {
265 + /* Not a file on the command line; do not derefernce the link.
266 + */
267 + return lgetfilecon(name, p);
268 + }
269 +}
270 +
271 +/* optionl_getfilecon() implements the getfilecon operation when the
272 + * -L option is in effect. That option makes us examine the thing the
273 + * symbolic link points to, not the symbolic link itself.
274 + */
275 +int
276 +optionl_getfilecon(const char *name, security_context_t *p)
277 +{
278 + int rv = getfilecon(name, p);
279 + if (0 == rv)
280 + return 0; /* normal case. */
281 + else
282 + return fallback_getfilecon(name, p, rv);
283 +}
284 +
285 +/* optionp_getfilecon() implements the stat operation when the -P
286 + * option is in effect (this is also the default). That option makes
287 + * us examine the symbolic link itself, not the thing it points to.
288 + */
289 +int
290 +optionp_getfilecon(const char *name, security_context_t *p)
291 +{
292 + return lgetfilecon(name, p);
293 +}
294 +#endif /* WITH_SELINUX */
295 +
296
297 static boolean
298 parse_and (const struct parser_table* entry, char **argv, int *arg_ptr)
299 @@ -1128,6 +1237,10 @@ tests (N can be +N or -N or N): -amin N
300 -readable -writable -executable\n\
301 -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N\n\
302 -used N -user NAME -xtype [bcdpfls]\n"));
303 +#ifdef WITH_SELINUX
304 + puts (_("\
305 + -context CONTEXT\n"));
306 +#endif /*WITH_SELINUX*/
307 puts (_("\
308 actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print \n\
309 -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit\n\
310 @@ -2552,6 +2665,29 @@ parse_version (const struct parser_table
311 exit (0);
312 }
313
314 +#ifdef WITH_SELINUX
315 +
316 +static boolean
317 +parse_scontext ( const struct parser_table* entry, char **argv, int *arg_ptr)
318 +{
319 + struct predicate *our_pred;
320 +
321 + if ( (argv == NULL) || (argv[*arg_ptr] == NULL) )
322 + return( false );
323 +
324 + our_pred = insert_primary(entry);
325 + our_pred->need_stat = false;
326 +#ifdef DEBUG
327 + our_pred->p_name = find_pred_name (pred_scontext);
328 +#endif /*DEBUG*/
329 + our_pred->args.scontext = argv[*arg_ptr];;
330 +
331 + (*arg_ptr)++;
332 + return( true );
333 +}
334 +
335 +#endif /*WITH_SELINUX*/
336 +
337 static boolean
338 parse_xdev (const struct parser_table* entry, char **argv, int *arg_ptr)
339 {
340 @@ -2803,7 +2939,11 @@ insert_fprintf (struct format_val *vec,
341 if (*scan2 == '.')
342 for (scan2++; ISDIGIT (*scan2); scan2++)
343 /* Do nothing. */ ;
344 +#ifdef WITH_SELINUX
345 + if (strchr ("abcdDfFgGhHiklmMnpPsStuUyYZ", *scan2))
346 +#else
347 if (strchr ("abcdDfFgGhHiklmMnpPsStuUyY", *scan2))
348 +#endif
349 {
350 segmentp = make_segment (segmentp, format, scan2 - format,
351 KIND_FORMAT, *scan2, 0,
352 diff -purN findutils-4.4.2.orig/find/pred.c findutils-4.4.2/find/pred.c
353 --- findutils-4.4.2.orig/find/pred.c 2009-05-16 15:17:01.000000000 +0000
354 +++ findutils-4.4.2/find/pred.c 2010-04-25 03:58:33.764899827 +0000
355 @@ -48,6 +48,14 @@
356 #include "error.h"
357 #include "verify.h"
358
359 +#ifdef WITH_SELINUX
360 +#include <selinux/selinux.h>
361 +#endif /*WITH_SELINUX*/
362 +
363 +#ifndef FNM_CASEFOLD
364 +#define FNM_CASEFOLD (1<<4)
365 +#endif /*FNM_CASEFOLD*/
366 +
367 #if ENABLE_NLS
368 # include <libintl.h>
369 # define _(Text) gettext (Text)
370 @@ -230,6 +238,9 @@ struct pred_assoc pred_table[] =
371 {pred_user, "user "},
372 {pred_writable, "writable "},
373 {pred_xtype, "xtype "},
374 +#ifdef WITH_SELINUX
375 + {pred_scontext, "context"},
376 +#endif /*WITH_SELINUX*/
377 {0, "none "}
378 };
379 #endif
380 @@ -1054,6 +1065,26 @@ do_fprintf(struct format_val *dest,
381 mode_to_filetype(stat_buf->st_mode & S_IFMT));
382 }
383 break;
384 +#ifdef WITH_SELINUX
385 + case 'Z': /* SELinux security context */
386 + {
387 + security_context_t scontext;
388 + int rv;
389 + rv = (*options.x_getfilecon)(state.rel_pathname, &scontext);
390 +
391 + if ( rv < 0 ) {
392 + fprintf(stderr, "getfileconf(%s): %s",
393 + pathname, strerror(errno));
394 + fflush(stderr);
395 + }
396 + else {
397 + segment->text[segment->text_len] = 's';
398 + checked_fprintf (dest, segment->text, scontext);
399 + freecon(scontext);
400 + }
401 + }
402 + break ;
403 +#endif /* WITH_SELINUX */
404 }
405 /* end of KIND_FORMAT case */
406 break;
407 @@ -1844,6 +1875,31 @@ pred_xtype (const char *pathname, struct
408 */
409 return (pred_type (pathname, &sbuf, pred_ptr));
410 }
411 +
412 +
413 +#ifdef WITH_SELINUX
414 +
415 +boolean
416 +pred_scontext (const char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
417 +{
418 + int rv;
419 + security_context_t scontext;
420 +
421 + rv = (* options.x_getfilecon)(state.rel_pathname, &scontext);
422 +
423 + if ( rv < 0 ) {
424 + (void) fprintf(stderr, "getfilecon(%s): %s\n", pathname, strerror(errno));
425 + (void) fflush(stderr);
426 + return ( false );
427 + }
428 +
429 + rv = (fnmatch(pred_ptr->args.scontext, scontext,0)==0);
430 + freecon(scontext);
431 + return rv;
432 +}
433 +
434 +#endif /*WITH_SELINUX*/
435 +
436
437 /* 1) fork to get a child; parent remembers the child pid
438 2) child execs the command requested
439 diff -purN findutils-4.4.2.orig/find/tree.c findutils-4.4.2/find/tree.c
440 --- findutils-4.4.2.orig/find/tree.c 2009-05-16 15:17:01.000000000 +0000
441 +++ findutils-4.4.2/find/tree.c 2010-04-25 03:58:33.764899827 +0000
442 @@ -1195,6 +1195,10 @@ build_expression_tree(int argc, char *ar
443 const struct parser_table *entry_close, *entry_print, *entry_open;
444 int i, oldi;
445
446 +#ifdef WITH_SELINUX
447 + int is_selinux_enabled_flag = is_selinux_enabled()>0;
448 +#endif /* WITH_SELINUX */
449 +
450 predicates = NULL;
451
452 /* Find where in ARGV the predicates begin by skipping the list of
453 @@ -1230,6 +1234,16 @@ build_expression_tree(int argc, char *ar
454 }
455
456 predicate_name = argv[i];
457 +
458 +#ifdef WITH_SELINUX
459 + if (! is_selinux_enabled_flag) {
460 + if ((strncmp(predicate_name,"-context",strlen("-context"))==0) ||
461 + (strncmp(predicate_name,"--context",strlen("--context"))==0)) {
462 + error (1, 0,_("Error: invalid predicate %s: the kernel is not selinux-enabled.\n"),predicate_name);
463 + }
464 + }
465 +#endif
466 +
467 parse_entry = find_parser (predicate_name);
468 if (parse_entry == NULL)
469 {
470 @@ -1434,6 +1448,9 @@ get_new_pred (const struct parser_table
471 last_pred->need_stat = true;
472 last_pred->need_type = true;
473 last_pred->args.str = NULL;
474 +#ifdef WITH_SELINUX
475 + last_pred->args.scontext = NULL;
476 +#endif
477 last_pred->pred_next = NULL;
478 last_pred->pred_left = NULL;
479 last_pred->pred_right = NULL;