]> git.pld-linux.org Git - packages/coreutils.git/blob - coreutils-selinux.patch
- selinux support
[packages/coreutils.git] / coreutils-selinux.patch
1 --- coreutils-5.0/src/Makefile.am.selinux       2003-05-21 11:20:27.000000000 -0400
2 +++ coreutils-5.0/src/Makefile.am       2003-05-21 11:20:28.000000000 -0400
3 @@ -4,13 +4,13 @@
4  EXTRA_SCRIPTS = nohup
5  
6  bin_SCRIPTS = groups @OPTIONAL_BIN_ZCRIPTS@
7 -bin_PROGRAMS = chgrp chown chmod cp dd dircolors du \
8 +bin_PROGRAMS = chgrp chown chmod chcon cp dd dircolors du \
9    ginstall link ln dir vdir ls mkdir \
10    mkfifo mknod mv readlink rm rmdir shred stat sync touch unlink \
11    cat cksum comm csplit cut expand fmt fold head join md5sum \
12    nl od paste pr ptx sha1sum sort split sum tac tail tr tsort unexpand uniq wc \
13    basename date dirname echo env expr factor false getgid \
14 -  hostname id kill logname pathchk printenv printf pwd seq sleep tee \
15 +  hostname id kill logname pathchk printenv printf pwd runcon seq sleep tee \
16    test true tty whoami yes \
17    @OPTIONAL_BIN_PROGS@ @DF_PROG@
18  
19 @@ -24,15 +24,15 @@ EXTRA_DIST = dcgen dircolors.hin tac-pip
20    groups.sh nohup.sh wheel-gen.pl
21  CLEANFILES = $(SCRIPTS) su
22  
23 -INCLUDES = -I.. -I$(srcdir) -I$(top_srcdir)/lib -I../lib
24 -DEFS = -DLOCALEDIR=\"$(localedir)\" -DSHAREDIR=\"$(datadir)\" @DEFS@
25 +INCLUDES = -I.. -I$(srcdir) -I$(top_srcdir)/lib -I../lib 
26 +DEFS = -DLOCALEDIR=\"$(localedir)\" -DSHAREDIR=\"$(datadir)\" -DWITH_SELINUX @DEFS@
27  
28  # Sometimes, the expansion of @LIBINTL@ includes -lc which may
29  # include modules defining variables like `optind', so libfetish.a
30  # must precede @LIBINTL@ in order to ensure we use GNU getopt.
31  # But libfetish.a must also follow @LIBINTL@, since libintl uses
32  # replacement functions defined in libfetish.a.
33 -LDADD = ../lib/libfetish.a @LIBINTL@ ../lib/libfetish.a
34 +LDADD = ../lib/libfetish.a @LIBINTL@ ../lib/libfetish.a -lselinux -lattr
35  
36  dir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
37  ls_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@
38 --- coreutils-5.0/src/Makefile.in.selinux       2003-05-21 11:20:26.000000000 -0400
39 +++ coreutils-5.0/src/Makefile.in       2003-05-21 11:23:03.000000000 -0400
40 @@ -56,7 +56,7 @@ CFLAGS = @CFLAGS@
41  CPP = @CPP@
42  CPPFLAGS = @CPPFLAGS@
43  CYGPATH_W = @CYGPATH_W@
44 -DEFS = -DLOCALEDIR=\"$(localedir)\" -DSHAREDIR=\"$(datadir)\" @DEFS@
45 +DEFS = -DLOCALEDIR=\"$(localedir)\" -DSHAREDIR=\"$(datadir)\" -DWITH_SELINUX @DEFS@
46  DEPDIR = @DEPDIR@
47  DF_PROG = @DF_PROG@
48  ECHO_C = @ECHO_C@
49 @@ -159,13 +159,13 @@ EXTRA_PROGRAMS = chroot df hostid nice p
50  EXTRA_SCRIPTS = nohup
51  
52  bin_SCRIPTS = groups @OPTIONAL_BIN_ZCRIPTS@
53 -bin_PROGRAMS = chgrp chown chmod cp dd dircolors du \
54 +bin_PROGRAMS = chgrp chown chmod chcon cp dd dircolors du \
55    ginstall link ln dir vdir ls mkdir \
56    mkfifo mknod mv readlink rm rmdir shred stat sync touch unlink \
57    cat cksum comm csplit cut expand fmt fold head join md5sum \
58    nl od paste pr ptx sha1sum sort split sum tac tail tr tsort unexpand uniq wc \
59    basename date dirname echo env expr factor false \
60 -  hostname id kill logname pathchk printenv printf pwd seq sleep tee \
61 +  hostname id kill logname pathchk printenv printf pwd runcon seq sleep tee \
62    test true tty whoami yes \
63    @OPTIONAL_BIN_PROGS@ @DF_PROG@
64  
65 @@ -189,7 +189,7 @@ INCLUDES = -I.. -I$(srcdir) -I$(top_srcd
66  # must precede @LIBINTL@ in order to ensure we use GNU getopt.
67  # But libfetish.a must also follow @LIBINTL@, since libintl uses
68  # replacement functions defined in libfetish.a.
69 -LDADD = ../lib/libfetish.a @LIBINTL@ ../lib/libfetish.a
70 +LDADD = ../lib/libfetish.a @LIBINTL@ ../lib/libfetish.a -lselinux -lattr
71  
72  dir_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ -ltermcap
73  ls_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ -ltermcap
74 @@ -291,7 +291,7 @@ CONFIG_CLEAN_FILES =
75  EXTRA_PROGRAMS = chroot$(EXEEXT) df$(EXEEXT) hostid$(EXEEXT) \
76         nice$(EXEEXT) pinky$(EXEEXT) stty$(EXEEXT) su$(EXEEXT) \
77         uname$(EXEEXT) uptime$(EXEEXT) users$(EXEEXT) who$(EXEEXT)
78 -bin_PROGRAMS = chgrp$(EXEEXT) chown$(EXEEXT) chmod$(EXEEXT) cp$(EXEEXT) \
79 +bin_PROGRAMS = chgrp$(EXEEXT) chown$(EXEEXT) chmod$(EXEEXT) chcon$(EXEEXT) cp$(EXEEXT) \
80         dd$(EXEEXT) dircolors$(EXEEXT) du$(EXEEXT) ginstall$(EXEEXT) \
81         link$(EXEEXT) ln$(EXEEXT) dir$(EXEEXT) vdir$(EXEEXT) \
82         ls$(EXEEXT) mkdir$(EXEEXT) mkfifo$(EXEEXT) mknod$(EXEEXT) \
83 @@ -307,7 +307,7 @@ bin_PROGRAMS = chgrp$(EXEEXT) chown$(EXE
84         date$(EXEEXT) dirname$(EXEEXT) echo$(EXEEXT) env$(EXEEXT) \
85         expr$(EXEEXT) factor$(EXEEXT) false$(EXEEXT) hostname$(EXEEXT) \
86         id$(EXEEXT) kill$(EXEEXT) logname$(EXEEXT) pathchk$(EXEEXT) \
87 -       printenv$(EXEEXT) printf$(EXEEXT) pwd$(EXEEXT) seq$(EXEEXT) \
88 +       printenv$(EXEEXT) printf$(EXEEXT) pwd$(EXEEXT) runcon$(EXEEXT) seq$(EXEEXT) \
89         sleep$(EXEEXT) tee$(EXEEXT) test$(EXEEXT) true$(EXEEXT) \
90         tty$(EXEEXT) whoami$(EXEEXT) yes$(EXEEXT) @OPTIONAL_BIN_PROGS@ \
91         @DF_PROG@
92 @@ -338,6 +338,11 @@ chown_OBJECTS = $(am_chown_OBJECTS)
93  chown_LDADD = $(LDADD)
94  chown_DEPENDENCIES = ../lib/libfetish.a ../lib/libfetish.a
95  chown_LDFLAGS =
96 +chcon_SOURCES = chcon.c
97 +chcon_OBJECTS = chcon.$(OBJEXT)
98 +chcon_LDADD = $(LDADD)
99 +chcon_DEPENDENCIES = ../lib/libfetish.a
100 +chcon_LDFLAGS =
101  chroot_SOURCES = chroot.c
102  chroot_OBJECTS = chroot.$(OBJEXT)
103  chroot_LDADD = $(LDADD)
104 @@ -589,6 +594,11 @@ rmdir_OBJECTS = rmdir.$(OBJEXT)
105  rmdir_LDADD = $(LDADD)
106  rmdir_DEPENDENCIES = ../lib/libfetish.a ../lib/libfetish.a
107  rmdir_LDFLAGS =
108 +runcon_SOURCES = runcon.c
109 +runcon_OBJECTS =  runcon$U.$(OBJEXT)
110 +runcon_LDADD = $(LDADD)
111 +runcon_DEPENDENCIES =  ../lib/libfetish.a
112 +runcon_LDFLAGS =
113  seq_SOURCES = seq.c
114  seq_OBJECTS = seq.$(OBJEXT)
115  seq_DEPENDENCIES = ../lib/libfetish.a ../lib/libfetish.a
116 @@ -793,7 +803,7 @@ COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUD
117         $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
118  CCLD = $(CC)
119  LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
120 -DIST_SOURCES = basename.c cat.c $(chgrp_SOURCES) chmod.c \
121 +DIST_SOURCES = basename.c cat.c $(chgrp_SOURCES) chmod.c chcon.c \
122         $(chown_SOURCES) chroot.c cksum.c comm.c $(cp_SOURCES) csplit.c \
123         cut.c date.c dd.c df.c $(dir_SOURCES) dircolors.c dirname.c \
124         du.c echo.c env.c expand.c expr.c factor.c false.c fmt.c fold.c \
125 @@ -801,7 +811,7 @@ DIST_SOURCES = basename.c cat.c $(chgrp_
126         kill.c link.c ln.c logname.c $(ls_SOURCES) $(md5sum_SOURCES) \
127         mkdir.c mkfifo.c mknod.c $(mv_SOURCES) nice.c nl.c od.c paste.c \
128         pathchk.c pinky.c pr.c printenv.c printf.c ptx.c pwd.c \
129 -       readlink.c $(rm_SOURCES) rmdir.c seq.c $(sha1sum_SOURCES) \
130 +       readlink.c $(rm_SOURCES) rmdir.c runcon.c seq.c $(sha1sum_SOURCES) \
131         shred.c sleep.c sort.c split.c stat.c stty.c su.c sum.c sync.c \
132         tac.c tail.c tee.c test.c touch.c tr.c true.c tsort.c tty.c \
133         uname.c unexpand.c uniq.c unlink.c uptime.c users.c \
134 @@ -809,7 +819,7 @@ DIST_SOURCES = basename.c cat.c $(chgrp_
135  HEADERS = $(noinst_HEADERS)
136  
137  DIST_COMMON = $(noinst_HEADERS) Makefile.am Makefile.in
138 -SOURCES = basename.c cat.c $(chgrp_SOURCES) chmod.c $(chown_SOURCES) chroot.c cksum.c comm.c $(cp_SOURCES) csplit.c cut.c date.c dd.c df.c $(dir_SOURCES) dircolors.c dirname.c du.c echo.c env.c expand.c expr.c factor.c false.c fmt.c fold.c $(ginstall_SOURCES) head.c hostid.c hostname.c id.c join.c kill.c link.c ln.c logname.c $(ls_SOURCES) $(md5sum_SOURCES) mkdir.c mkfifo.c mknod.c $(mv_SOURCES) nice.c nl.c od.c paste.c pathchk.c pinky.c pr.c printenv.c printf.c ptx.c pwd.c readlink.c $(rm_SOURCES) rmdir.c seq.c $(sha1sum_SOURCES) shred.c sleep.c sort.c split.c stat.c stty.c su.c sum.c sync.c tac.c tail.c tee.c test.c touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c uniq.c unlink.c uptime.c users.c $(vdir_SOURCES) wc.c who.c whoami.c yes.c
139 +SOURCES = basename.c cat.c $(chgrp_SOURCES) chmod.c chcon.c $(chown_SOURCES) chroot.c cksum.c comm.c $(cp_SOURCES) csplit.c cut.c date.c dd.c df.c $(dir_SOURCES) dircolors.c dirname.c du.c echo.c env.c expand.c expr.c factor.c false.c fmt.c fold.c $(ginstall_SOURCES) head.c hostid.c hostname.c id.c join.c kill.c link.c ln.c logname.c $(ls_SOURCES) $(md5sum_SOURCES) mkdir.c mkfifo.c mknod.c $(mv_SOURCES) nice.c nl.c od.c paste.c pathchk.c pinky.c pr.c printenv.c printf.c ptx.c pwd.c readlink.c $(rm_SOURCES) rmdir.c runcon.c seq.c $(sha1sum_SOURCES) shred.c sleep.c sort.c split.c stat.c stty.c su.c sum.c sync.c tac.c tail.c tee.c test.c touch.c tr.c true.c tsort.c tty.c uname.c unexpand.c uniq.c unlink.c uptime.c users.c $(vdir_SOURCES) wc.c who.c whoami.c yes.c
140  
141  all: $(BUILT_SOURCES)
142         $(MAKE) $(AM_MAKEFLAGS) all-am
143 @@ -872,6 +882,9 @@ chgrp$(EXEEXT): $(chgrp_OBJECTS) $(chgrp
144  chmod$(EXEEXT): $(chmod_OBJECTS) $(chmod_DEPENDENCIES) 
145         @rm -f chmod$(EXEEXT)
146         $(LINK) $(chmod_LDFLAGS) $(chmod_OBJECTS) $(chmod_LDADD) $(LIBS)
147 +chcon$(EXEEXT): $(chcon_OBJECTS) $(chcon_DEPENDENCIES) 
148 +       @rm -f chcon$(EXEEXT)
149 +       $(LINK) $(chcon_LDFLAGS) $(chcon_OBJECTS) $(chcon_LDADD) $(LIBS)
150  chown$(EXEEXT): $(chown_OBJECTS) $(chown_DEPENDENCIES) 
151         @rm -f chown$(EXEEXT)
152         $(LINK) $(chown_LDFLAGS) $(chown_OBJECTS) $(chown_LDADD) $(LIBS)
153 @@ -1028,6 +1041,9 @@ rm$(EXEEXT): $(rm_OBJECTS) $(rm_DEPENDEN
154  rmdir$(EXEEXT): $(rmdir_OBJECTS) $(rmdir_DEPENDENCIES) 
155         @rm -f rmdir$(EXEEXT)
156         $(LINK) $(rmdir_LDFLAGS) $(rmdir_OBJECTS) $(rmdir_LDADD) $(LIBS)
157 +runcon$(EXEEXT): $(runcon_OBJECTS) $(runcon_DEPENDENCIES) 
158 +       @rm -f runcon$(EXEEXT)
159 +       $(LINK) $(runcon_LDFLAGS) $(runcon_OBJECTS) $(runcon_LDADD) $(LIBS)
160  seq$(EXEEXT): $(seq_OBJECTS) $(seq_DEPENDENCIES) 
161         @rm -f seq$(EXEEXT)
162         $(LINK) $(seq_LDFLAGS) $(seq_OBJECTS) $(seq_LDADD) $(LIBS)
163 --- /dev/null   2003-01-30 05:24:37.000000000 -0500
164 +++ coreutils-5.0/src/chcon.c   2003-05-21 11:20:28.000000000 -0400
165 @@ -0,0 +1,324 @@
166 +/* chcontext -- change security context of a pathname */
167 +
168 +#include <config.h>
169 +#include <stdio.h>
170 +#include <sys/types.h>
171 +#include <grp.h>
172 +#include <getopt.h>
173 +#include <selinux/selinux.h>
174 +
175 +#include "system.h"
176 +#include "error.h"
177 +#include "savedir.h"
178 +#include "group-member.h"
179 +
180 +enum Change_status
181 +{
182 +  CH_SUCCEEDED,
183 +  CH_FAILED,
184 +  CH_NO_CHANGE_REQUESTED
185 +};
186 +
187 +enum Verbosity
188 +{
189 +  /* Print a message for each file that is processed.  */
190 +  V_high,
191 +
192 +  /* Print a message for each file whose attributes we change.  */
193 +  V_changes_only,
194 +
195 +  /* Do not be verbose.  This is the default. */
196 +  V_off
197 +};
198 +
199 +static int change_dir_context PARAMS ((const char *dir, security_context_t context,
200 +                                      const struct stat *statp));
201 +
202 +/* The name the program was run with. */
203 +char *program_name;
204 +
205 +/* If nonzero, and the systems has support for it, change the context
206 +   of symbolic links rather than any files they point to.  */
207 +static int change_symlinks;
208 +
209 +/* If nonzero, change the context of directories recursively. */
210 +static int recurse;
211 +
212 +/* If nonzero, force silence (no error messages). */
213 +static int force_silent;
214 +
215 +/* Level of verbosity.  */
216 +static enum Verbosity verbosity = V_off;
217 +
218 +/* The name of the context file is being given. */
219 +static const char *contextname;
220 +
221 +/* The argument to the --reference option.  Use the context of this file.
222 +   This file must exist.  */
223 +static char *reference_file;
224 +
225 +/* If nonzero, display usage information and exit.  */
226 +static int show_help;
227 +
228 +/* If nonzero, print the version on standard output and exit.  */
229 +static int show_version;
230 +
231 +static struct option const long_options[] =
232 +{
233 +  {"recursive", no_argument, 0, 'R'},
234 +  {"changes", no_argument, 0, 'c'},
235 +  {"no-dereference", no_argument, 0, 'h'},
236 +  {"silent", no_argument, 0, 'f'},
237 +  {"quiet", no_argument, 0, 'f'},
238 +  {"reference", required_argument, 0, CHAR_MAX + 1},
239 +  {"context", required_argument, 0, CHAR_MAX + 2},
240 +  {"verbose", no_argument, 0, 'v'},
241 +  {"help", no_argument, &show_help, 1},
242 +  {"version", no_argument, &show_version, 1},
243 +  {0, 0, 0, 0}
244 +};
245 +
246 +/* Tell the user how/if the context of FILE has been changed.
247 +   CHANGED describes what (if anything) has happened. */
248 +
249 +static void
250 +describe_change (const char *file, enum Change_status changed)
251 +{
252 +  const char *fmt;
253 +  switch (changed)
254 +    {
255 +    case CH_SUCCEEDED:
256 +      fmt = _("context of %s changed to %s\n");
257 +      break;
258 +    case CH_FAILED:
259 +      fmt = _("failed to change context of %s to %s\n");
260 +      break;
261 +    case CH_NO_CHANGE_REQUESTED:
262 +      fmt = _("context of %s retained as %s\n");
263 +      break;
264 +    default:
265 +      abort ();
266 +    }
267 +  printf (fmt, file, contextname);
268 +}
269 +
270 +/* Change the context of FILE to CONTEXT.
271 +   If it is a directory and -R is given, recurse.
272 +   Return 0 if successful, 1 if errors occurred. */
273 +
274 +static int
275 +change_file_context (const char *file, security_context_t context)
276 +{
277 +  struct stat file_stats;
278 +  security_context_t file_context=NULL;
279 +  int errors = 0;
280 +
281 +  if (lgetfilecon(file, &file_context)<0)
282 +    {
283 +      if (force_silent == 0)
284 +       error (0, errno, "%s", file);
285 +      return 1;
286 +    }
287 +
288 +  if (strcmp(context,file_context)!=0)
289 +    {
290 +      int fail;
291 +
292 +      if (change_symlinks)
293 +       fail = lsetfilecon (file, context);
294 +      else
295 +       fail = setfilecon (file, context);
296 +
297 +      if (verbosity == V_high || (verbosity == V_changes_only && !fail))
298 +       describe_change (file, (fail ? CH_FAILED : CH_SUCCEEDED));
299 +
300 +      if (fail)
301 +       {
302 +         errors = 1;
303 +         if (force_silent == 0)
304 +           {
305 +             error (0, errno, "%s", file);
306 +           }
307 +       }
308 +    }
309 +  else if (verbosity == V_high)
310 +    {
311 +      describe_change (file, CH_NO_CHANGE_REQUESTED);
312 +    }
313 +
314 +  freecon(file_context);
315 +
316 +  if (recurse) {
317 +    if (lstat(file, &file_stats)==0)
318 +      if (S_ISDIR (file_stats.st_mode))
319 +                errors |= change_dir_context (file, context, &file_stats);
320 +  }
321 +  return errors;
322 +}
323 +
324 +/* Recursively change context of the files in directory DIR
325 +   to CONTEXT CONTEXT.
326 +   STATP points to the results of lstat on DIR.
327 +   Return 0 if successful, 1 if errors occurred. */
328 +
329 +static int
330 +change_dir_context (const char *dir, security_context_t context, const struct stat *statp)
331 +{
332 +  char *name_space, *namep;
333 +  char *path;                  /* Full path of each entry to process. */
334 +  unsigned dirlength;          /* Length of `dir' and '\0'. */
335 +  unsigned filelength;         /* Length of each pathname to process. */
336 +  unsigned pathlength;         /* Bytes allocated for `path'. */
337 +  int errors = 0;
338 +
339 +  errno = 0;
340 +  name_space = savedir (dir);
341 +  if (name_space == NULL)
342 +    {
343 +      if (errno)
344 +        {
345 +         if (force_silent == 0)
346 +           error (0, errno, "%s", dir);
347 +         return 1;
348 +       }
349 +      else
350 +       error (1, 0, _("virtual memory exhausted"));
351 +    }
352 +
353 +  dirlength = strlen (dir) + 1;        /* + 1 is for the trailing '/'. */
354 +  pathlength = dirlength + 1;
355 +  /* Give `path' a dummy value; it will be reallocated before first use. */
356 +  path = xmalloc (pathlength);
357 +  strcpy (path, dir);
358 +  path[dirlength - 1] = '/';
359 +
360 +  for (namep = name_space; *namep; namep += filelength - dirlength)
361 +    {
362 +      filelength = dirlength + strlen (namep) + 1;
363 +      if (filelength > pathlength)
364 +       {
365 +         pathlength = filelength * 2;
366 +         path = xrealloc (path, pathlength);
367 +       }
368 +      strcpy (path + dirlength, namep);
369 +      errors |= change_file_context (path, context);
370 +    }
371 +  free (path);
372 +  free (name_space);
373 +  return errors;
374 +}
375 +
376 +static void
377 +usage (int status)
378 +{
379 +  if (status != 0)
380 +    fprintf (stderr, _("Try `%s --help' for more information.\n"),
381 +            program_name);
382 +  else
383 +    {
384 +      printf (_("\
385 +Usage: %s [OPTION]... CONTEXT FILE...\n\
386 +  or:  %s [OPTION]... --reference=RFILE FILE...\n\
387 +  or:  %s [OPTION]... --context=CONTEXT FILE...\n\
388 +"),
389 +       program_name, program_name, program_name);
390 +      printf (_("\
391 +Change the security context of each FILE to CONTEXT.\n\
392 +\n\
393 +  -c, --changes          like verbose but report only when a change is made\n\
394 +  -h, --no-dereference   affect symbolic links instead of any referenced file\n\
395 +                         (available only on systems with lchown system call)\n\
396 +  -f, --silent, --quiet  suppress most error messages\n\
397 +      --reference=RFILE  use RFILE's group instead of using a CONTEXT value\n\
398 +      --context=CONTEXT          use context corresponding to CONTEXT for CONTEXT value\n\
399 +  -R, --recursive        change files and directories recursively\n\
400 +  -v, --verbose          output a diagnostic for every file processed\n\
401 +      --help             display this help and exit\n\
402 +      --version          output version information and exit\n\
403 +"));
404 +      close_stdout ();
405 +    }
406 +  exit (status);
407 +}
408 +
409 +int
410 +main (int argc, char **argv)
411 +{
412 +  security_context_t context = NULL;
413 +  security_context_t ref_context = NULL;
414 +  int errors = 0;
415 +  int optc;
416 +  
417 +  program_name = argv[0];
418 +  setlocale (LC_ALL, "");
419 +  bindtextdomain (PACKAGE, LOCALEDIR);
420 +  textdomain (PACKAGE);
421 +
422 +  recurse = force_silent = 0;
423 +  
424 +  while ((optc = getopt_long (argc, argv, "Rcfhv", long_options, NULL)) != -1)
425 +  {
426 +         switch (optc)
427 +         {
428 +         case 0:
429 +                 break;
430 +         case CHAR_MAX + 1:
431 +                 reference_file = optarg;
432 +                 break;
433 +         case CHAR_MAX +2:
434 +                 context = optarg;
435 +                 break;
436 +         case 'R':
437 +                 recurse = 1;
438 +                 break;
439 +         case 'c':
440 +                 verbosity = V_changes_only;
441 +                 break;
442 +         case 'f':
443 +                 force_silent = 1;
444 +                 break;
445 +         case 'h':
446 +                 change_symlinks = 1;
447 +                 break;
448 +         case 'v':
449 +                 verbosity = V_high;
450 +                 break;
451 +         default:
452 +                 usage (1);
453 +         }
454 +  }
455 +
456 +  if (show_version)
457 +  {
458 +     printf ("chcon (%s) %s\n", GNU_PACKAGE, VERSION);
459 +     close_stdout ();
460 +     exit (0);
461 +  }
462 +
463 +  if (show_help)
464 +    usage (0);
465 +
466 +  if (argc - optind + ( (reference_file || ( context > 0 ) ) ? 1 : 0) <= 1)
467 +  {
468 +     error (0, 0, _("too few arguments"));
469 +     usage (1);
470 +  }
471 +  
472 +  if (reference_file)
473 +    {
474 +      if (getfilecon (reference_file, &ref_context)<0)
475 +       error (1, errno, "%s", reference_file);
476 +
477 +      context = ref_context;
478 +    }
479 +
480 +  context = argv[optind++];
481 +  for (; optind < argc; ++optind)
482 +     errors |= change_file_context (argv[optind], context);
483 +
484 +  if (verbosity != V_off)
485 +    close_stdout ();
486 +  if (ref_context != NULL)
487 +    freecon(ref_context);
488 +  exit (errors);
489 +}
490 --- coreutils-5.0/src/copy.c.selinux    2003-05-21 11:20:27.000000000 -0400
491 +++ coreutils-5.0/src/copy.c    2003-05-21 11:20:28.000000000 -0400
492 @@ -46,6 +46,10 @@
493  #include "same.h"
494  #include "xreadlink.h"
495  
496 +#ifdef WITH_SELINUX
497 +#include <selinux/selinux.h>          /* for is_selinux_enabled() */
498 +#endif
499 +
500  #define DO_CHOWN(Chown, File, New_uid, New_gid)                                \
501    (Chown (File, New_uid, New_gid)                                      \
502     /* If non-root uses -p, it's ok if we can't preserve ownership.     \
503 @@ -1463,6 +1467,24 @@ copy_internal (const char *src_path, con
504              preserving owner/group is a potential security problem.  */
505  # endif
506         }
507 +#ifdef WITH_SELINUX
508 +      /* Trying to preserve a security context can fail for any UID, and user
509 +       * should probably always know about it.
510 +       */
511 +      if ( x->preserve_security_context ) {
512 +       security_context_t lcontext;
513 +        if ( lgetfilecon(src_path, &lcontext) < 0 ) {
514 +          error (0, errno, _("getting security context for %s"), src_path);
515 +          return 1;
516 +        }
517 +        if ( lsetfilecon(dst_path, lcontext) < 0 ) {
518 +          error (0, errno, _("preserving security context for %s (context==%s)"), dst_path, lcontext);
519 +         freecon(lcontext);
520 +          return 1;
521 +        }
522 +       freecon(lcontext);
523 +      }
524 +#endif
525      }
526    else
527  #endif
528 @@ -1551,6 +1573,27 @@ copy_internal (const char *src_path, con
529    }
530  #endif
531  
532 +#ifdef WITH_SELINUX
533 +   /* Trying to preserve a security context can fail for any UID, and user
534 +    * should probably always know about it.
535 +    */
536
537 +   if ( x->preserve_security_context ) {
538 +     security_context_t lcontext;
539 +     if ( getfilecon(src_path, &lcontext) < 0 ) {
540 +       error (0, errno, _("getting security context for %s"), src_path);
541 +       return 1;
542 +     }
543 +     if ( setfilecon(dst_path, lcontext) < 0 ) {
544 +       error (0, errno, _("preserving security context for %s (context==%s)"), dst_path, lcontext);
545 +       freecon(lcontext);
546 +       return 1;
547 +     }
548 +     freecon(lcontext);
549 +   }
550 +
551 +#endif
552 +
553    if (x->preserve_mode || x->move_mode)
554      {
555        if (copy_acl (src_path, dst_path, src_mode) && x->require_preserve)
556 --- coreutils-5.0/src/copy.h.selinux    2003-05-21 11:20:27.000000000 -0400
557 +++ coreutils-5.0/src/copy.h    2003-05-21 11:20:28.000000000 -0400
558 @@ -105,6 +105,9 @@ struct cp_options
559    int preserve_ownership;
560    int preserve_mode;
561    int preserve_timestamps;
562 +#ifdef WITH_SELINUX
563 +  int preserve_security_context;
564 +#endif
565  
566    /* Enabled for mv, and for cp by the --preserve=links option.
567       If nonzero, attempt to preserve in the destination files any
568 --- coreutils-5.0/src/cp.c.selinux      2003-05-21 11:20:27.000000000 -0400
569 +++ coreutils-5.0/src/cp.c      2003-05-21 11:31:26.000000000 -0400
570 @@ -52,6 +52,10 @@
571  
572  #define AUTHORS N_ ("Torbjorn Granlund, David MacKenzie, and Jim Meyering")
573  
574 +#ifdef WITH_SELINUX
575 +#include <selinux/selinux.h>          /* for is_selinux_enabled() */
576 +#endif
577 +
578  #ifndef _POSIX_VERSION
579  uid_t geteuid ();
580  #endif
581 @@ -149,6 +153,9 @@ static struct option const long_opts[] =
582    {"update", no_argument, NULL, 'u'},
583    {"verbose", no_argument, NULL, 'v'},
584    {"version-control", required_argument, NULL, 'V'}, /* Deprecated. FIXME. */
585 +#ifdef WITH_SELINUX
586 +  {"context", required_argument, NULL, 'X'},
587 +#endif
588    {GETOPT_HELP_OPTION_DECL},
589    {GETOPT_VERSION_OPTION_DECL},
590    {NULL, 0, NULL, 0}
591 @@ -198,6 +205,9 @@ Mandatory arguments to long options are 
592                                   additional attributes: links, all\n\
593  "), stdout);
594        fputs (_("\
595 +  -c                           same as --preserve=context\n\
596 +"), stdout);
597 +      fputs (_("\
598        --no-preserve=ATTR_LIST  don't preserve the specified attributes\n\
599        --parents                append source path to DIRECTORY\n\
600    -P                           same as `--no-dereference'\n\
601 @@ -225,6 +235,7 @@ Mandatory arguments to long options are 
602                                   destination file is missing\n\
603    -v, --verbose                explain what is being done\n\
604    -x, --one-file-system        stay on this file system\n\
605 +  -X, --context=CONTEXT        set security context of copy to CONTEXT\n\
606  "), stdout);
607        fputs (HELP_OPTION_DESCRIPTION, stdout);
608        fputs (VERSION_OPTION_DESCRIPTION, stdout);
609 @@ -358,6 +369,28 @@ re_protect (const char *const_dst_path, 
610             }
611         }
612  
613 +#ifdef WITH_SELINUX
614 +      /* Trying to preserve a security context can fail for any UID, and user
615 +       * should probably always know about it.
616 +       */
617 +
618 +      if ( x->preserve_security_context ) {
619 +       int rv;
620 +       security_context_t context;
621 +
622 +       if ( (rv = getfilecon(src_path, &context)) < 0 ) {
623 +         error (0, errno, _("getting security context for %s"), src_path);
624 +         return 1;
625 +       }
626 +
627 +       if ( (rv = setfilecon(dst_path, context)) < 0 ) {
628 +         error (0, errno, _("preserving security context for %s (context==%s)"), dst_path, context);
629 +         return 1;
630 +       }
631 +       freecon(context);
632 +      }
633 +#endif
634 +
635        dst_path[p->slash_offset] = '/';
636      }
637    return 0;
638 @@ -756,8 +789,8 @@ do_copy (int n_files, char **file, const
639         {
640           new_dest = (char *) dest;
641         }
642 -
643 -      return copy (source, new_dest, new_dst, x, &unused, NULL);
644 +      ret=copy (source, new_dest, new_dst, x, &unused, NULL);
645 +      return ret;
646      }
647  
648    /* unreachable */
649 @@ -781,6 +814,10 @@ cp_option_init (struct cp_options *x)
650    x->preserve_mode = 0;
651    x->preserve_timestamps = 0;
652  
653 +#ifdef WITH_SELINUX
654 +  x->preserve_security_context = 0;
655 +#endif
656 +
657    x->require_preserve = 0;
658    x->recursive = 0;
659    x->sparse_mode = SPARSE_AUTO;
660 @@ -808,19 +845,20 @@ decode_preserve_arg (char const *arg, st
661        PRESERVE_TIMESTAMPS,
662        PRESERVE_OWNERSHIP,
663        PRESERVE_LINK,
664 +      PRESERVE_CONTEXT,
665        PRESERVE_ALL
666      };
667    static enum File_attribute const preserve_vals[] =
668      {
669        PRESERVE_MODE, PRESERVE_TIMESTAMPS,
670 -      PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_ALL
671 +      PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_ALL
672      };
673  
674    /* Valid arguments to the `--preserve' option. */
675    static char const* const preserve_args[] =
676      {
677        "mode", "timestamps",
678 -      "ownership", "links", "all", 0
679 +      "ownership", "links", "context", "all", 0
680      };
681  
682    char *arg_writable = xstrdup (arg);
683 @@ -855,11 +893,16 @@ decode_preserve_arg (char const *arg, st
684           x->preserve_links = on_off;
685           break;
686  
687 +       case PRESERVE_CONTEXT:
688 +         x->preserve_security_context = on_off;
689 +         break;
690 +
691         case PRESERVE_ALL:
692           x->preserve_mode = on_off;
693           x->preserve_timestamps = on_off;
694           x->preserve_ownership = on_off;
695           x->preserve_links = on_off;
696 +         x->preserve_security_context = on_off;
697           break;
698  
699         default:
700 @@ -882,6 +925,10 @@ main (int argc, char **argv)
701    struct cp_options x;
702    int copy_contents = 0;
703    char *target_directory = NULL;
704 +#ifdef WITH_SELINUX
705 +  security_context_t scontext = NULL;
706 +  int is_selinux_enabled_flag= is_selinux_enabled();
707 +#endif
708  
709    program_name = argv[0];
710    setlocale (LC_ALL, "");
711 @@ -896,7 +943,11 @@ main (int argc, char **argv)
712       we'll actually use backup_suffix_string.  */
713    backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
714  
715 +#ifdef WITH_SELINUX
716 +  while ((c = getopt_long (argc, argv, "abcdfHilLprsuvxPRS:V:X:Z:", long_opts, NULL))
717 +#else
718    while ((c = getopt_long (argc, argv, "abdfHilLprsuvxPRS:V:", long_opts, NULL))
719 +#endif
720          != -1)
721      {
722        switch (c)
723 @@ -988,6 +1039,36 @@ main (int argc, char **argv)
724           x.preserve_timestamps = 1;
725           x.require_preserve = 1;
726           break;
727 +#ifdef WITH_SELINUX
728 +       case 'c':
729 +         if ( scontext != NULL ) { 
730 +             (void) fprintf(stderr, "%s: cannot force target context <-- %s and preserve it\n", argv[0], scontext);
731 +           exit( 1 );
732 +         }
733 +         else if (is_selinux_enabled_flag) 
734 +           x.preserve_security_context = 1;
735 +         break;
736 +
737 +       case 'X':
738 +         /* politely decline if we're not on a selinux-enabled kernel. */
739 +         if( !is_selinux_enabled_flag ) {
740 +           fprintf( stderr, "Warning:  ignoring --context (-X). "
741 +                            "It requires a SELinux enabled kernel.\n" );
742 +           break;
743 +         }
744 +         if ( x.preserve_security_context ) {
745 +           (void) fprintf(stderr, "%s: cannot force target context to '%s' and preserve it\n", argv[0], optarg);
746 +           exit( 1 );
747 +         }
748 +         scontext = optarg;
749 +         /* if there's a security_context given set new path 
750 +            components to that context, too */
751 +         if ( setfscreatecon(scontext) < 0 ) {
752 +           (void) fprintf(stderr, _("cannot set default security context %s"), scontext);
753 +           exit( 1 );
754 +         }
755 +         break;
756 +#endif
757  
758         case PARENTS_OPTION:
759           flag_path = 1;
760 --- coreutils-5.0/src/id.c.selinux      2003-03-27 17:39:46.000000000 -0500
761 +++ coreutils-5.0/src/id.c      2003-05-21 11:20:28.000000000 -0400
762 @@ -46,6 +46,20 @@ gid_t getegid ();
763  
764  int getugroups ();
765  
766 +#ifdef WITH_SELINUX
767 +#include <selinux/selinux.h>
768 +static void print_context PARAMS ((char* context));
769 +/* Print the SELinux context */
770 +static void
771 +print_context(char *context)
772 +{
773 +  printf ("%s", context);
774 +}
775 +
776 +/* If nonzero, output only the SELinux context. -c */
777 +static int just_context = 0;
778 +
779 +#endif
780  static void print_user (uid_t uid);
781  static void print_group (gid_t gid);
782  static void print_group_list (const char *username);
783 @@ -64,8 +78,14 @@ static gid_t rgid, egid;
784  /* The number of errors encountered so far. */
785  static int problems = 0;
786  
787 +/* The SELinux context */
788 +/* Set `context' to a known invalid value so print_full_info() will *
789 + * know when `context' has not been set to a meaningful value.      */
790 +static security_context_t context=NULL;
791 +
792  static struct option const longopts[] =
793  {
794 +  {"context", no_argument, NULL, 'c'},
795    {"group", no_argument, NULL, 'g'},
796    {"groups", no_argument, NULL, 'G'},
797    {"name", no_argument, NULL, 'n'},
798 @@ -89,6 +109,7 @@ usage (int status)
799  Print information for USERNAME, or the current user.\n\
800  \n\
801    -a              ignore, for compatibility with other versions\n\
802 +  -c, --context   print only the context\n\
803    -g, --group     print only the effective group ID\n\
804    -G, --groups    print all group IDs\n\
805    -n, --name      print a name instead of a number, for -ugG\n\
806 @@ -110,6 +131,7 @@ int
807  main (int argc, char **argv)
808  {
809    int optc;
810 +  int is_selinux_enabled_flag=is_selinux_enabled();
811  
812    /* If nonzero, output the list of all group IDs. -G */
813    int just_group_list = 0;
814 @@ -127,7 +149,7 @@ main (int argc, char **argv)
815  
816    atexit (close_stdout);
817  
818 -  while ((optc = getopt_long (argc, argv, "agnruG", longopts, NULL)) != -1)
819 +  while ((optc = getopt_long (argc, argv, "acgnrsuG", longopts, NULL)) != -1)
820      {
821        switch (optc)
822         {
823 @@ -136,6 +158,17 @@ main (int argc, char **argv)
824         case 'a':
825           /* Ignore -a, for compatibility with SVR4.  */
826           break;
827 +#ifdef WITH_SELINUX
828 +        case 'c':
829 +         /* politely decline if we're not on a selinux-enabled kernel. */
830 +         if( !is_selinux_enabled_flag ) {
831 +           fprintf( stderr, "Sorry, --context (-c) can be used only on "
832 +                            "a selinux-enabled kernel.\n" );
833 +           exit( 1 );
834 +         }
835 +          just_context = 1;
836 +          break;
837 +#endif
838         case 'g':
839           just_group = 1;
840           break;
841 @@ -158,8 +191,28 @@ main (int argc, char **argv)
842         }
843      }
844  
845 -  if (just_user + just_group + just_group_list > 1)
846 -    error (EXIT_FAILURE, 0, _("cannot print only user and only group"));
847 +#ifdef WITH_SELINUX
848 +  if (argc - optind == 1)
849 +    is_selinux_enabled_flag = 0;
850 +
851 +  if( just_context  && !is_selinux_enabled_flag)
852 +    error (1, 0, _("\
853 +cannot display context when selinux not enabled or when displaying the id\n\
854 +of a different user"));
855 +
856 +  /* If we are on a selinux-enabled kernel, get our context.    *
857 +   * Otherwise, leave the context variable alone - it has *
858 +   * been initialized known invalid value; if we see this invalid   *
859 +   * value later, we will know we are on a non-selinux kernel.         */
860 +  if( is_selinux_enabled_flag )
861 +    {
862 +      if (getcon(&context))
863 +        error (1, 0, "can't get process context");
864 +    }
865 +#endif
866 +
867 +  if (just_user + just_group + just_group_list + just_context > 1)
868 +    error (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
869  
870    if (just_user + just_group + just_group_list == 0 && (use_real || use_name))
871      error (EXIT_FAILURE, 0,
872 @@ -190,6 +243,10 @@ main (int argc, char **argv)
873      print_group (use_real ? rgid : egid);
874    else if (just_group_list)
875      print_group_list (argv[optind]);
876 +#ifdef WITH_SELINUX
877 +  else if (just_context)
878 +    print_context (context);
879 +#endif
880    else
881      print_full_info (argv[optind]);
882    putchar ('\n');
883 @@ -397,4 +454,9 @@ print_full_info (const char *username)
884      free (groups);
885    }
886  #endif /* HAVE_GETGROUPS */
887 +#ifdef WITH_SELINUX
888 +  if ( context != NULL ) {
889 +    printf(" context=%s",context);
890 +  }
891 +#endif
892  }
893 --- coreutils-5.0/src/install.c.selinux 2003-05-21 11:20:27.000000000 -0400
894 +++ coreutils-5.0/src/install.c 2003-05-21 11:20:28.000000000 -0400
895 @@ -50,6 +50,10 @@
896  # include <sys/wait.h>
897  #endif
898  
899 +#ifdef WITH_SELINUX
900 +#include <selinux/selinux.h>          /* for is_selinux_enabled() */
901 +#endif
902 +
903  struct passwd *getpwnam ();
904  struct group *getgrnam ();
905  
906 @@ -126,11 +130,17 @@ static int dir_arg;
907  static struct option const long_options[] =
908  {
909    {"backup", optional_argument, NULL, 'b'},
910 +#ifdef WITH_SELINUX
911 +  {"context", required_argument, NULL, 'X'},
912 +#endif
913    {"directory", no_argument, NULL, 'd'},
914    {"group", required_argument, NULL, 'g'},
915    {"mode", required_argument, NULL, 'm'},
916    {"owner", required_argument, NULL, 'o'},
917    {"preserve-timestamps", no_argument, NULL, 'p'},
918 +#ifdef WITH_SELINUX
919 +  {"preserve_context", no_argument, NULL, 'P'},
920 +#endif
921    {"strip", no_argument, NULL, 's'},
922    {"suffix", required_argument, NULL, 'S'},
923    {"version-control", required_argument, NULL, 'V'}, /* Deprecated. FIXME. */
924 @@ -247,6 +257,9 @@ cp_option_init (struct cp_options *x)
925  
926    x->update = 0;
927    x->verbose = 0;
928 +#ifdef WITH_SELINUX
929 +  x->preserve_security_context = 0;
930 +#endif
931    x->xstat = stat;
932    x->dest_info = NULL;
933    x->src_info = NULL;
934 @@ -265,6 +278,11 @@ main (int argc, char **argv)
935    struct cp_options x;
936    int n_files;
937    char **file;
938 +#ifdef WITH_SELINUX
939 +  security_context_t scontext = NULL;
940 + /* set iff kernel has extra selinux system calls */
941 +  int is_selinux_enabled_flag = is_selinux_enabled();
942 +#endif
943  
944    program_name = argv[0];
945    setlocale (LC_ALL, "");
946 @@ -285,7 +303,11 @@ main (int argc, char **argv)
947       we'll actually use backup_suffix_string.  */
948    backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
949  
950 +#ifdef WITH_SELINUX
951 +  while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pPX:vV:S:Z:", long_options,
952 +#else
953    while ((optc = getopt_long (argc, argv, "bcCsDdg:m:o:pvV:S:", long_options,
954 +#endif
955                               NULL)) != -1)
956      {
957        switch (optc)
958 @@ -338,6 +360,39 @@ main (int argc, char **argv)
959           make_backups = 1;
960           backup_suffix_string = optarg;
961           break;
962 +#ifdef WITH_SELINUX
963 +       case 'P':
964 +       /* politely decline if we're not on a selinux-enabled kernel. */
965 +         if( !is_selinux_enabled_flag ) {
966 +           fprintf( stderr, "Warning:  ignoring --preserve_context (-P) "
967 +                            "because the kernel is not selinux-enabled.\n" );
968 +           break;
969 +         }
970 +         if ( scontext!=NULL ) { /* scontext could be NULL because of calloc() failure */
971 +             (void) fprintf(stderr, "%s: cannot force target context to '%s' and preserve it\n", argv[0], scontext);
972 +           exit( 1 );
973 +         }
974 +         x.preserve_security_context = 1;
975 +         break ;
976 +       case 'X':
977 +         /* politely decline if we're not on a selinux-enabled kernel. */
978 +         if( !is_selinux_enabled_flag ) {
979 +           fprintf( stderr, "Warning:  ignoring --context (-X) "
980 +                            "because the kernel is not selinux-enabled.\n" );
981 +           break;
982 +         }
983 +         if ( x.preserve_security_context ) {
984 +
985 +                   (void) fprintf(stderr, "%s: cannot force target context == '%s' and preserve it\n", argv[0], optarg);
986 +           exit( 1 );
987 +         }
988 +         scontext = optarg;
989 +         if (setfscreatecon(scontext)) {
990 +           (void) fprintf(stderr, "%s: cannot setup default context == '%s'\n", argv[0], scontext);
991 +           exit(1);
992 +         }
993 +         break;
994 +#endif
995         case_GETOPT_HELP_CHAR;
996         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
997         default:
998 @@ -721,6 +776,11 @@ Mandatory arguments to long options are 
999    -S, --suffix=SUFFIX override the usual backup suffix\n\
1000    -v, --verbose       print the name of each directory as it is created\n\
1001  "), stdout);
1002 +      fputs (_("\
1003 +  -P, --preserve_context (Selinux) Preserve security context\n\
1004 +  -X, --context=CONTEXT  (Selinux) Set security context of files and directories\n\
1005 +"), stdout);
1006 +
1007        fputs (HELP_OPTION_DESCRIPTION, stdout);
1008        fputs (VERSION_OPTION_DESCRIPTION, stdout);
1009        fputs (_("\
1010 --- coreutils-5.0/src/ls.c.selinux      2003-05-21 11:20:27.000000000 -0400
1011 +++ coreutils-5.0/src/ls.c      2003-05-21 11:20:28.000000000 -0400
1012 @@ -132,6 +132,12 @@ int wcwidth ();
1013  
1014  #define AUTHORS N_ ("Richard Stallman and David MacKenzie")
1015  
1016 +#ifdef WITH_SELINUX
1017 +#include <selinux/selinux.h>
1018 +int is_selinux_enabled_flag= 0;
1019 +static int print_scontext       = 0;
1020 +#endif
1021 +
1022  #define obstack_chunk_alloc malloc
1023  #define obstack_chunk_free free
1024  
1025 @@ -229,6 +235,10 @@ struct fileinfo
1026      /* For long listings, true if the file has an access control list.  */
1027      bool have_acl;
1028  #endif
1029 +
1030 +#ifdef WITH_SELINUX
1031 +    security_context_t scontext;
1032 +#endif
1033    };
1034  
1035  #if HAVE_ACL || USE_ACL
1036 @@ -292,6 +302,9 @@ static void queue_directory (const char 
1037  static void sort_files (void);
1038  static void parse_ls_color (void);
1039  void usage (int status);
1040 +#ifdef WITH_SELINUX
1041 +static void print_scontext_format PARAMS ((const struct fileinfo *f));
1042 +#endif
1043  
1044  /* The name the program was run with, stripped of any leading path. */
1045  char *program_name;
1046 @@ -381,7 +394,12 @@ enum format
1047      one_per_line,              /* -1 */
1048      many_per_line,             /* -C */
1049      horizontal,                        /* -x */
1050 -    with_commas                        /* -m */
1051 +#ifdef WITH_SELINUX
1052 +    with_commas,               /* -m */
1053 +    security_format
1054 +#else
1055 +    with_commas                        /* -m */
1056 +#endif
1057    };
1058  
1059  static enum format format;
1060 @@ -706,6 +724,11 @@ enum
1061    SHOW_CONTROL_CHARS_OPTION,
1062    SI_OPTION,
1063    SORT_OPTION,
1064 +#ifdef WITH_SELINUX
1065 +  CONTEXT_OPTION,
1066 +  LCONTEXT_OPTION,
1067 +  SCONTEXT_OPTION,
1068 +#endif
1069    TIME_OPTION,
1070    TIME_STYLE_OPTION
1071  };
1072 @@ -749,6 +772,11 @@ static struct option const long_options[
1073    {"time-style", required_argument, 0, TIME_STYLE_OPTION},
1074    {"color", optional_argument, 0, COLOR_OPTION},
1075    {"block-size", required_argument, 0, BLOCK_SIZE_OPTION},
1076 +#ifdef WITH_SELINUX
1077 +  {"context", no_argument, 0, CONTEXT_OPTION},
1078 +  {"lcontext", no_argument, 0, LCONTEXT_OPTION},
1079 +  {"scontext", no_argument, 0, SCONTEXT_OPTION},
1080 +#endif
1081    {"author", no_argument, 0, AUTHOR_OPTION},
1082    {GETOPT_HELP_OPTION_DECL},
1083    {GETOPT_VERSION_OPTION_DECL},
1084 @@ -758,12 +786,19 @@ static struct option const long_options[
1085  static char const *const format_args[] =
1086  {
1087    "verbose", "long", "commas", "horizontal", "across",
1088 -  "vertical", "single-column", 0
1089 +  "vertical", "single-column", 
1090 +#ifdef WITH_SELINUX
1091 +  "context",
1092 +#endif
1093 +  0
1094  };
1095  
1096  static enum format const format_types[] =
1097  {
1098    long_format, long_format, with_commas, horizontal, horizontal,
1099 +#ifdef WITH_SELINUX
1100 +  security_format,
1101 +#endif
1102    many_per_line, one_per_line
1103  };
1104  
1105 @@ -1147,6 +1182,9 @@ main (int argc, char **argv)
1106  
1107    format_needs_stat = sort_type == sort_time || sort_type == sort_size
1108      || format == long_format
1109 +#ifdef WITH_SELINUX
1110 +    || format == security_format || print_scontext
1111 +#endif
1112      || dereference == DEREF_ALWAYS
1113      || print_block_size || print_inode;
1114    format_needs_type = (format_needs_stat == 0
1115 @@ -1269,6 +1307,11 @@ decode_switches (int argc, char **argv)
1116    /* Record whether there is an option specifying sort type.  */
1117    int sort_type_specified = 0;
1118  
1119 +#ifdef WITH_SELINUX
1120 +  /* 1 iff kernel has new selinux system calls */
1121 +  is_selinux_enabled_flag= is_selinux_enabled();
1122 +#endif
1123 +
1124    qmark_funny_chars = 0;
1125  
1126    /* initialize all switches to default settings */
1127 @@ -1319,6 +1362,9 @@ decode_switches (int argc, char **argv)
1128    all_files = 0;
1129    really_all_files = 0;
1130    ignore_patterns = 0;
1131 +#ifdef WITH_SELINUX
1132 +  print_scontext       = 0;
1133 +#endif
1134  
1135    /* FIXME: put this in a function.  */
1136    {
1137 @@ -1684,6 +1730,31 @@ decode_switches (int argc, char **argv)
1138  
1139         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
1140  
1141 +#ifdef WITH_SELINUX
1142 +
1143 +#define check_selinux() if (!is_selinux_enabled_flag) { \
1144 +           fprintf( stderr, "Sorry, this option can only be used " \
1145 +                            "on a SELinux kernel.\n" ); \
1146 +           exit( EXIT_FAILURE ); \
1147 +}
1148 +
1149 +       case CONTEXT_OPTION: /* new security format */
1150 +               check_selinux();
1151 +               print_scontext = 1;
1152 +               format = security_format;
1153 +               break;
1154 +       case LCONTEXT_OPTION: /* long format plus security context */
1155 +               check_selinux();
1156 +               print_scontext = 1;
1157 +               format = long_format;
1158 +               break;
1159 +       case SCONTEXT_OPTION: /* short form of new security format */
1160 +               check_selinux();
1161 +               print_scontext = 0;
1162 +               format = security_format;
1163 +               break;
1164 +#endif
1165 +
1166         default:
1167           usage (EXIT_FAILURE);
1168         }
1169 @@ -2331,6 +2402,10 @@ clear_files (void)
1170        free (files[i].name);
1171        if (files[i].linkname)
1172         free (files[i].linkname);
1173 +#ifdef WITH_SELINUX
1174 +      if (files[i].scontext)
1175 +       freecon (files[i].scontext);
1176 +#endif
1177      }
1178  
1179    files_index = 0;
1180 @@ -2402,6 +2477,11 @@ gobble_file (const char *name, enum file
1181             {
1182               int need_lstat;
1183               err = stat (path, &files[files_index].stat);
1184 +#ifdef WITH_SELINUX
1185 +             if (err>=0) 
1186 +               if (is_selinux_enabled_flag)
1187 +                 err=getfilecon(path, &files[files_index].scontext);
1188 +#endif
1189  
1190               if (dereference == DEREF_COMMAND_LINE_ARGUMENTS)
1191                 break;
1192 @@ -2420,6 +2500,12 @@ gobble_file (const char *name, enum file
1193  
1194         default: /* DEREF_NEVER */
1195           err = lstat (path, &files[files_index].stat);
1196 +#ifdef WITH_SELINUX
1197 +         if (err>=0) 
1198 +           if (is_selinux_enabled_flag)
1199 +             err=lgetfilecon(path, &files[files_index].scontext);
1200 +#endif
1201 +
1202           break;
1203         }
1204  
1205 @@ -2849,6 +2935,16 @@ print_current_files (void)
1206           DIRED_PUTCHAR ('\n');
1207         }
1208        break;
1209 +
1210 +#ifdef WITH_SELINUX
1211 +    case security_format:
1212 +      for (i = 0; i < files_index; i++)
1213 +      {
1214 +        print_scontext_format (files + i);
1215 +        DIRED_PUTCHAR ('\n');
1216 +      }
1217 +      break;
1218 +#endif
1219      }
1220  }
1221  
1222 @@ -3112,6 +3208,14 @@ print_long_format (const struct fileinfo
1223        p += strlen (p);
1224      }
1225  
1226 +#ifdef WITH_SELINUX
1227 +
1228 +  if ( print_scontext ) {
1229 +    sprintf (p, "%-32s ", f->scontext);
1230 +    p += strlen (p);
1231 +  }
1232 +#endif
1233 +
1234    DIRED_INDENT ();
1235    DIRED_FPUTS (buf, stdout, p - buf);
1236    print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
1237 @@ -3917,6 +4021,16 @@ Mandatory arguments to long options are 
1238    -X                         sort alphabetically by entry extension\n\
1239    -1                         list one file per line\n\
1240  "), stdout);
1241 +#ifdef WITH_SELINUX
1242 +printf(_("SELINUX options:\n\n\
1243 +      --lcontext             Display security context.   Enable -l. Lines\n\
1244 +                               will probably be too wide for most displays.\n\
1245 +      --context              Display security context so it fits on most\n\
1246 +                               displays.  Displays only mode, user, group,\n\
1247 +                               security context and file name.\n\
1248 +      --scontext             Display only security context and file name.\n\
1249 +"));
1250 +#endif
1251        fputs (HELP_OPTION_DESCRIPTION, stdout);
1252        fputs (VERSION_OPTION_DESCRIPTION, stdout);
1253        fputs (_("\n\
1254 @@ -3935,3 +4049,79 @@ to a terminal (tty).\n\
1255      }
1256    exit (status);
1257  }
1258 +
1259 +#ifdef WITH_SELINUX
1260 +
1261 +static void
1262 +print_scontext_format (const struct fileinfo *f)
1263 +{
1264 +  char modebuf[12];
1265 +
1266 +  /* 7 fields that may require LONGEST_HUMAN_READABLE bytes,
1267 +     1 10-byte mode string,
1268 +     9 spaces, one following each of these fields, and
1269 +     1 trailing NUL byte.  */
1270 +
1271 +  char init_bigbuf[7 * LONGEST_HUMAN_READABLE + 10  + 9 + 1];
1272 +  char *buf = init_bigbuf;
1273 +  size_t bufsize = sizeof (init_bigbuf);
1274 +  size_t s;
1275 +  char *p;
1276 +  const char *fmt;
1277 +  char *user_name;
1278 +  char *group_name;
1279 +  int rv;
1280 +  char *scontext;
1281 +
1282 +  p = buf;
1283 +
1284 +  if ( print_scontext ) { /* zero means terse listing */
1285 +    mode_string (f->stat.st_mode, modebuf);
1286 +    modebuf[10] = (FILE_HAS_ACL (f) ? '+' : ' ');
1287 +    modebuf[11] = '\0';
1288 +
1289 +    /* print mode */
1290 +
1291 +    (void) sprintf (p, "%s ", modebuf);
1292 +    p += strlen (p);
1293 +
1294 +    /* print standard user and group */
1295 +
1296 +    user_name = (numeric_ids ? NULL : getuser (f->stat.st_uid));
1297 +    if (user_name)
1298 +      (void) sprintf (p, "%-8.8s ", user_name);
1299 +    else
1300 +      (void) sprintf (p, "%-8u ", (unsigned int) f->stat.st_uid);
1301 +    p += strlen (p);
1302 +
1303 +    if ( print_group ) {
1304 +      group_name = (numeric_ids ? NULL : getgroup (f->stat.st_gid));
1305 +      if (group_name)
1306 +       (void) sprintf (p, "%-8.8s ", group_name);
1307 +      else
1308 +       (void) sprintf (p, "%-8u ", (unsigned int) f->stat.st_gid);
1309 +      p += strlen (p);
1310 +    }
1311 +  }
1312 +
1313 +  (void) sprintf (p, "%-32s ", f->scontext);
1314 +  p += strlen (p);
1315
1316 +  DIRED_INDENT ();
1317 +  DIRED_FPUTS (buf, stdout, p - buf);
1318 +  print_name_with_quoting (f->name, f->stat.st_mode, f->linkok, &dired_obstack);
1319
1320 +  if (f->filetype == symbolic_link) {
1321 +      if (f->linkname) {
1322 +         DIRED_FPUTS_LITERAL (" -> ", stdout);
1323 +         print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1, NULL);
1324 +         if (indicator_style != none)
1325 +           print_type_indicator (f->linkmode);
1326 +      }
1327 +  }
1328 +  else {
1329 +    if (indicator_style != none)
1330 +      print_type_indicator (f->stat.st_mode);
1331 +  }
1332 +}
1333 +#endif
1334 --- coreutils-5.0/src/mkdir.c.selinux   2002-09-23 03:35:27.000000000 -0400
1335 +++ coreutils-5.0/src/mkdir.c   2003-05-21 11:20:28.000000000 -0400
1336 @@ -34,6 +34,10 @@
1337  
1338  #define AUTHORS "David MacKenzie"
1339  
1340 +#ifdef WITH_SELINUX
1341 +#include <selinux/selinux.h>          /* for is_selinux_enabled() */
1342 +#endif
1343 +
1344  /* The name this program was run with. */
1345  char *program_name;
1346  
1347 @@ -42,6 +46,9 @@ static int create_parents;
1348  
1349  static struct option const longopts[] =
1350  {
1351 +#ifdef WITH_SELINUX
1352 +  {"context", required_argument, NULL, 'c'},
1353 +#endif
1354    {"mode", required_argument, NULL, 'm'},
1355    {"parents", no_argument, NULL, 'p'},
1356    {"verbose", no_argument, NULL, 'v'},
1357 @@ -63,6 +70,11 @@ usage (int status)
1358  Create the DIRECTORY(ies), if they do not already exist.\n\
1359  \n\
1360  "), stdout);
1361 +#ifdef WITH_SELINUX
1362 +      printf (_("\
1363 +  -c, --context=CONTEXT (Selinux) set security context to CONTEXT\n\
1364 +"));
1365 +#endif
1366        fputs (_("\
1367  Mandatory arguments to long options are mandatory for short options too.\n\
1368  "), stdout);
1369 @@ -97,7 +109,11 @@ main (int argc, char **argv)
1370  
1371    create_parents = 0;
1372  
1373 +#ifdef WITH_SELINUX
1374 +  while ((optc = getopt_long (argc, argv, "pm:s:c:v", longopts, NULL)) != -1)
1375 +#else
1376    while ((optc = getopt_long (argc, argv, "pm:v", longopts, NULL)) != -1)
1377 +#endif
1378      {
1379        switch (optc)
1380         {
1381 @@ -112,6 +128,20 @@ main (int argc, char **argv)
1382         case 'v': /* --verbose  */
1383           verbose_fmt_string = _("created directory %s");
1384           break;
1385 +#ifdef WITH_SELINUX
1386 +       case 'c':
1387 +         /* politely decline if we're not on a selinux-enabled kernel. */
1388 +         if( !is_selinux_enabled()) {
1389 +           fprintf( stderr, "Sorry, --context (-c) can be used only on "
1390 +                            "a selinux-enabled kernel.\n" );
1391 +           exit( 1 );
1392 +         }
1393 +         if (setfscreatecon(optarg)) {
1394 +           fprintf( stderr, "Sorry, cannot set default context to %s.\n", optarg);
1395 +           exit( 1 );
1396 +         }
1397 +         break;
1398 +#endif
1399         case_GETOPT_HELP_CHAR;
1400         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
1401         default:
1402 --- coreutils-5.0/src/mkfifo.c.selinux  2002-08-31 03:29:21.000000000 -0400
1403 +++ coreutils-5.0/src/mkfifo.c  2003-05-21 11:20:28.000000000 -0400
1404 @@ -32,11 +32,18 @@
1405  
1406  #define AUTHORS "David MacKenzie"
1407  
1408 +#ifdef WITH_SELINUX
1409 +#include <selinux/selinux.h>          /* for is_selinux_enabled() */
1410 +#endif
1411 +
1412  /* The name this program was run with. */
1413  char *program_name;
1414  
1415  static struct option const longopts[] =
1416  {
1417 +#ifdef WITH_SELINUX
1418 +  {"context", required_argument, NULL, 'c'},
1419 +#endif
1420    {"mode", required_argument, NULL, 'm'},
1421    {GETOPT_HELP_OPTION_DECL},
1422    {GETOPT_VERSION_OPTION_DECL},
1423 @@ -57,6 +64,11 @@ usage (int status)
1424  Create named pipes (FIFOs) with the given NAMEs.\n\
1425  \n\
1426  "), stdout);
1427 +#ifdef WITH_SELINUX
1428 +      printf (_("\
1429 +  -c, --context=CONTEXT   set security context (quoted string)\n\
1430 +"), stdout);
1431 +#endif
1432        fputs (_("\
1433  Mandatory arguments to long options are mandatory for short options too.\n\
1434  "), stdout);
1435 @@ -92,7 +104,11 @@ main (int argc, char **argv)
1436  #ifndef S_ISFIFO
1437    error (4, 0, _("fifo files not supported"));
1438  #else
1439 +#ifdef WITH_SELINUX
1440 +  while ((optc = getopt_long (argc, argv, "m:c:", longopts, NULL)) != -1)
1441 +#else
1442    while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
1443 +#endif
1444      {
1445        switch (optc)
1446         {
1447 @@ -101,6 +117,19 @@ main (int argc, char **argv)
1448         case 'm':
1449           specified_mode = optarg;
1450           break;
1451 +#ifdef WITH_SELINUX
1452 +       case 'c':
1453 +         if( !is_selinux_enabled()) {
1454 +           fprintf( stderr, "Sorry, --context (-c) can be used only on "
1455 +                            "a selinux-enabled kernel.\n" );
1456 +           exit( 1 );
1457 +         }
1458 +         if (setfscreatecon(optarg)) {
1459 +           fprintf( stderr, "Sorry, cannot set default context to %s.\n", optarg);
1460 +           exit( 1 );
1461 +         }
1462 +         break;
1463 +#endif
1464         case_GETOPT_HELP_CHAR;
1465         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
1466         default:
1467 --- coreutils-5.0/src/mknod.c.selinux   2002-12-14 09:14:59.000000000 -0500
1468 +++ coreutils-5.0/src/mknod.c   2003-05-21 11:20:28.000000000 -0400
1469 @@ -36,8 +36,15 @@
1470  /* The name this program was run with. */
1471  char *program_name;
1472  
1473 +#ifdef WITH_SELINUX
1474 +#include <selinux/selinux.h>
1475 +#endif
1476 +
1477  static struct option const longopts[] =
1478  {
1479 +#ifdef WITH_SELINUX
1480 +  {"context", required_argument, NULL, 'c'},
1481 +#endif
1482    {"mode", required_argument, NULL, 'm'},
1483    {GETOPT_HELP_OPTION_DECL},
1484    {GETOPT_VERSION_OPTION_DECL},
1485 @@ -58,6 +65,11 @@ usage (int status)
1486  Create the special file NAME of the given TYPE.\n\
1487  \n\
1488  "), stdout);
1489 +#ifdef WITH_SELINUX
1490 +      fputs(_("\
1491 +  -c, --context=CONTEXT   set security context (quoted string)\n\
1492 +"), stdout);
1493 +#endif
1494        fputs (_("\
1495  Mandatory arguments to long options are mandatory for short options too.\n\
1496  "), stdout);
1497 @@ -102,7 +114,11 @@ main (int argc, char **argv)
1498  
1499    specified_mode = NULL;
1500  
1501 +#ifdef WITH_SELINUX
1502 +  while ((optc = getopt_long (argc, argv, "m:s:c:", longopts, NULL)) != -1)
1503 +#else
1504    while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
1505 +#endif
1506      {
1507        switch (optc)
1508         {
1509 @@ -111,6 +127,20 @@ main (int argc, char **argv)
1510         case 'm':
1511           specified_mode = optarg;
1512           break;
1513 +#ifdef WITH_SELINUX
1514 +       case 'c':
1515 +         /* politely decline if we're not on a selinux-enabled kernel. */
1516 +         if( !is_selinux_enabled()) {
1517 +           fprintf( stderr, "Sorry, --context (-c) can be used only on "
1518 +                            "a selinux-enabled kernel.\n" );
1519 +           exit( 1 );
1520 +         }
1521 +         if (setfscreatecon(optarg)) {
1522 +           fprintf( stderr, "Sorry, cannot set default context to %s.\n", optarg);
1523 +           exit( 1 );
1524 +         }
1525 +         break;
1526 +#endif
1527         case_GETOPT_HELP_CHAR;
1528         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
1529         default:
1530 --- coreutils-5.0/src/mv.c.selinux      2003-05-21 11:20:27.000000000 -0400
1531 +++ coreutils-5.0/src/mv.c      2003-05-21 11:31:45.000000000 -0400
1532 @@ -37,6 +37,9 @@
1533  #include "path-concat.h"
1534  #include "quote.h"
1535  #include "remove.h"
1536 +#ifdef WITH_SELINUX
1537 +#include <selinux/selinux.h>        /* for is_selinux_enabled() */
1538 +#endif
1539  
1540  /* The official name of this program (e.g., no `g' prefix).  */
1541  #define PROGRAM_NAME "mv"
1542 @@ -139,6 +142,9 @@ cp_option_init (struct cp_options *x)
1543  
1544    x->update = 0;
1545    x->verbose = 0;
1546 +#ifdef WITH_SELINUX
1547 +  x->preserve_security_context = 0;
1548 +#endif
1549    x->xstat = lstat;
1550    x->dest_info = NULL;
1551    x->src_info = NULL;
1552 @@ -358,6 +364,10 @@ Mandatory arguments to long options are 
1553                                   equivalent to --reply=query\n\
1554  "), stdout);
1555        fputs (_("\
1556 +  -c                           preserve security context when source and\n\
1557 +                               destination are on different file systems\n\
1558 +"), stdout);
1559 +      fputs (_("\
1560        --reply={yes,no,query}   specify how to handle the prompt about an\n\
1561                                   existing destination file\n\
1562        --strip-trailing-slashes remove any trailing slashes from each SOURCE\n\
1563 @@ -421,7 +431,11 @@ main (int argc, char **argv)
1564  
1565    errors = 0;
1566  
1567 +#ifdef WITH_SELINUX
1568 +  while ((c = getopt_long (argc, argv, "bcfiuvS:V:", long_options, NULL)) != -1)
1569 +#else
1570    while ((c = getopt_long (argc, argv, "bfiuvS:V:", long_options, NULL)) != -1)
1571 +#endif
1572      {
1573        switch (c)
1574         {
1575 @@ -440,6 +454,15 @@ main (int argc, char **argv)
1576           if (optarg)
1577             version_control_string = optarg;
1578           break;
1579 +#ifdef WITH_SELINUX
1580 +       case 'c':
1581 +         if (is_selinux_enabled())
1582 +           x.preserve_security_context = 1;
1583 +         else
1584 +           fprintf( stderr, "Warning:  ignoring -c. "
1585 +                            "It requires a SELinux enabled kernel.\n" );
1586 +         break;
1587 +#endif
1588         case 'f':
1589           x.interactive = I_ALWAYS_YES;
1590           break;
1591 --- /dev/null   2003-01-30 05:24:37.000000000 -0500
1592 +++ coreutils-5.0/src/runcon.c  2003-05-21 11:20:28.000000000 -0400
1593 @@ -0,0 +1,169 @@
1594 +/*
1595 + * runcon [ context |
1596 + *         ( [ -r role ] [-t type] [ -u user ] [ -l levelrange ] )
1597 + *         command [arg1 [arg2 ...] ]
1598 + *
1599 + * attempt to run the specified command with the specified context.
1600 + * 
1601 + * -r role  : use the current context with the specified role
1602 + * -t type  : use the current context with the specified type
1603 + * -u user  : use the current context with the specified user
1604 + * -l level : use the current context with the specified level range
1605 + *
1606 + * Contexts are interpreted as follows:
1607 + *
1608 + * Number of       MLS
1609 + * components    system?
1610 + *
1611 + *     1            -         type
1612 + *     2            -         role:type
1613 + *     3            Y         role:type:range
1614 + *     3            N         user:role:type
1615 + *     4            Y         user:role:type:range
1616 + *     4            N         error
1617 + */
1618 +
1619 +#include <unistd.h>
1620 +#include <stdio.h>
1621 +#include <getopt.h>
1622 +#include <selinux/context.h>
1623 +#include <selinux/selinux.h>
1624 +#include <errno.h>
1625 +extern int errno;
1626 +
1627 +/* The name the program was run with. */
1628 +char *program_name;
1629 +
1630 +void
1631 +usage(char *str)
1632 +{
1633 +  printf("Usage: %s [OPTION]... command [args]\n"
1634 +         "Run a program in a different security context.\n\n"
1635 +         "  context       Complete security context\n"
1636 +         "  -t            type (for same role as parent)\n"
1637 +         "  -u            user identity\n"
1638 +         "  -r            role\n"
1639 +         "  -l            levelrange\n"
1640 +         "    --help      display this help and exit\n",
1641 +         program_name);
1642 +  exit(1);
1643 +}
1644 +
1645 +int 
1646 +main(int argc,char **argv,char **envp )
1647 +{
1648 +  char *role    = 0;
1649 +  char *range   = 0;
1650 +  char *user    = 0;
1651 +  char *type    = 0;
1652 +  char *context = NULL;
1653 +  security_context_t cur_context = NULL;
1654 +
1655 +  context_t      con;
1656 +
1657 +  program_name = argv[0];
1658 +  
1659 +  while (1) {
1660 +    int c;
1661 +    int this_option_optind = optind ? optind : 1;
1662 +    int option_index = 0;
1663 +    static struct option long_options[] = {
1664 +      { "role", 1, 0, 'r' },
1665 +      { "type", 1, 0, 't' },
1666 +      { "user", 1, 0, 'u' },
1667 +      { "range", 1, 0, 'l' },
1668 +      { "help", 0, 0, '?' },
1669 +      { 0, 0, 0, 0 }
1670 +    };
1671 +    c = getopt_long(argc, argv, "s:r:t:u:l:?", long_options, &option_index);
1672 +    if ( c == -1 ) {
1673 +      break;
1674 +    }
1675 +    switch ( c ) {
1676 +    case 'r':
1677 +      if ( role ) {
1678 +       fprintf(stderr,"multiple roles\n");
1679 +       exit(1);
1680 +      }
1681 +      role = optarg;
1682 +      break;
1683 +    case 't':
1684 +      if ( type ) {
1685 +       fprintf(stderr,"multiple types\n");
1686 +       exit(1);
1687 +      }
1688 +      type = optarg;
1689 +      break;
1690 +    case 'u':
1691 +      if ( user ) {
1692 +       fprintf(stderr,"multiple users\n");
1693 +       exit(1);
1694 +      }
1695 +      user = optarg;
1696 +      break;
1697 +    case 'l':
1698 +      if ( range ) {
1699 +       fprintf(stderr,"multiple levelranges\n");
1700 +       exit(1);
1701 +      }
1702 +      range = optarg;
1703 +      break;
1704 +    default:
1705 +      fprintf(stderr,"unrecognised option %c\n",c);
1706 +    case '?':
1707 +      usage(0);
1708 +      break;
1709 +    }
1710 +  }
1711 +  if ( !(user || role || type || range)) {
1712 +    if ( optind >= argc ) {
1713 +      usage("must specify -t, -u, -l, -r, or context");
1714 +    }
1715 +    context = argv[optind++];
1716 +  }
1717 +  
1718 +  if ( optind >= argc ) {
1719 +    usage("no command found");
1720 +  }
1721 +
1722 +  if ( context ) {
1723 +    con = context_new(context);
1724 +    if (!con) {
1725 +      fprintf(stderr,"%s is not a valid context\n", context);
1726 +      exit(1);
1727 +    }
1728 +  }
1729 +  else {
1730 +    getcon(&cur_context);
1731 +    con = context_new(cur_context);
1732 +    if (!con) {
1733 +      fprintf(stderr,"%s is not a valid context\n", context);
1734 +      exit(1);
1735 +    }
1736 +    if ( user ) {
1737 +      context_user_set(con,user);
1738 +    }
1739 +    if ( type ) {
1740 +      context_type_set(con,type);
1741 +    }
1742 +    if ( range ) {
1743 +      context_range_set(con,range);
1744 +    }
1745 +    if ( role ) {
1746 +      context_role_set(con,role);
1747 +    }
1748 +  }
1749 +  
1750 +  if (setexeccon(context_str(con))!=0) {
1751 +    fprintf(stderr,"unable to setup security context %s\n", context_str(con));
1752 +    exit(1);
1753 +  }
1754 +  if (cur_context!=NULL) 
1755 +    freecon(cur_context);
1756 +
1757 +  if ( execvp(argv[optind],argv+optind) ) {
1758 +    perror("execvp");
1759 +    exit(1);
1760 +  }
1761 +  return 1; /* can't reach this statement.... */
1762 +}
1763 --- /dev/null   2003-01-30 05:24:37.000000000 -0500
1764 +++ coreutils-5.0/man/chcon.x   2003-05-21 11:20:28.000000000 -0400
1765 @@ -0,0 +1,4 @@
1766 +[NAME]
1767 +chcon \- change file security context
1768 +[DESCRIPTION]
1769 +.\" Add any additional description here
1770 --- /dev/null   2003-01-30 05:24:37.000000000 -0500
1771 +++ coreutils-5.0/man/runcon.x  2003-05-21 11:20:28.000000000 -0400
1772 @@ -0,0 +1,2 @@
1773 +[DESCRIPTION]
1774 +.\" Add any additional description here
1775 --- coreutils-5.0/tests/cp/Makefile.am.selinux  2003-02-02 15:08:59.000000000 -0500
1776 +++ coreutils-5.0/tests/cp/Makefile.am  2003-05-21 11:20:28.000000000 -0400
1777 @@ -3,8 +3,8 @@ AUTOMAKE_OPTIONS = 1.1 gnits
1778  
1779  TESTS = \
1780    preserve-2 r-vs-symlink link-preserve \
1781 -  backup-1 no-deref-link1 no-deref-link2 no-deref-link3 backup-is-src \
1782 -  same-file cp-mv-backup symlink-slash slink-2-slink fail-perm dir-slash \
1783 +  backup-1 backup-is-src \
1784 +  cp-mv-backup symlink-slash slink-2-slink fail-perm dir-slash \
1785    perm cp-HL special-bits link dir-rm-dest cp-parents deref-slink \
1786    dir-vs-file into-self
1787  EXTRA_DIST = $(TESTS)
1788 --- coreutils-5.0/tests/cp/Makefile.in.selinux  2003-04-02 09:28:43.000000000 -0500
1789 +++ coreutils-5.0/tests/cp/Makefile.in  2003-05-21 11:23:03.000000000 -0400
1790 @@ -152,8 +152,8 @@ AUTOMAKE_OPTIONS = 1.1 gnits
1791  
1792  TESTS = \
1793    preserve-2 r-vs-symlink link-preserve \
1794 -  backup-1 no-deref-link1 no-deref-link2 no-deref-link3 backup-is-src \
1795 -  same-file cp-mv-backup symlink-slash slink-2-slink fail-perm dir-slash \
1796 +  backup-1 backup-is-src \
1797 +  cp-mv-backup symlink-slash slink-2-slink fail-perm dir-slash \
1798    perm cp-HL special-bits link dir-rm-dest cp-parents deref-slink \
1799    dir-vs-file into-self
1800  
1801 --- coreutils-5.0/README.selinux        2003-03-29 09:24:00.000000000 -0500
1802 +++ coreutils-5.0/README        2003-05-21 11:20:28.000000000 -0400
1803 @@ -7,11 +7,11 @@ arbitrary limits.
1804  
1805  The programs that can be built with this package are:
1806  
1807 -  basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd
1808 +  basename cat chcon chgrp chmod chown chroot cksum comm cp csplit cut date dd
1809    df dir dircolors dirname du echo env expand expr factor false fmt fold
1810    ginstall groups head hostid hostname id join kill link ln logname ls
1811    md5sum mkdir mkfifo mknod mv nice nl nohup od paste pathchk pinky pr
1812 -  printenv printf ptx pwd readlink rm rmdir seq sha1sum shred sleep sort
1813 +  printenv printf ptx pwd readlink rm rmdir runcon seq sha1sum shred sleep sort
1814    split stat stty su sum sync tac tail tee test touch tr true tsort tty
1815    uname unexpand uniq unlink uptime users vdir wc who whoami yes
1816  
This page took 0.211881 seconds and 4 git commands to generate.