1 diff -Nuarp tizen-coreutils/src/copy.c tizen-coreutils-smack/src/copy.c
2 --- tizen-coreutils/src/copy.c 2012-11-30 11:18:57.473521424 +0200
3 +++ tizen-coreutils-smack/src/copy.c 2012-11-30 11:26:01.601502515 +0200
11 # define HAVE_FCHOWN false
12 @@ -570,6 +574,28 @@ copy_reg (char const *src_name, char con
16 + if (x->preserve_context)
18 + char src_context[SMACK_LABELLEN];
19 + char dst_context[SMACK_LABELLEN];
21 + if (smack_of_fd (source_desc, src_context, SMACK_LABELLEN) < 0)
23 + if (x->require_preserve)
24 + ; //fail silently now // return_val = false;
26 + else if (smack_of_fd (dest_desc, dst_context, SMACK_LABELLEN) < 0)
28 + if (x->require_preserve)
29 + ; //fail silently now // return_val = false;
31 + else if (strcmp(src_context, dst_context))
33 + if (smack_to_fd(dest_desc, src_context) < 0 && x->require_preserve)
34 + ; //fail silently now // return_val = false;
38 close_src_and_dst_desc:
39 if (close (dest_desc) < 0)
41 diff -Nuarp tizen-coreutils/src/copy.h tizen-coreutils-smack/src/copy.h
42 --- tizen-coreutils/src/copy.h 2012-11-30 10:11:38.000000000 +0200
43 +++ tizen-coreutils-smack/src/copy.h 2012-11-30 11:20:39.837516860 +0200
44 @@ -128,6 +128,10 @@ struct cp_options
46 bool preserve_timestamps;
48 + /* If true, attempt to give the copies the original files'
49 + security context. */
50 + bool preserve_context;
52 /* Enabled for mv, and for cp by the --preserve=links option.
53 If true, attempt to preserve in the destination files any
54 logical hard links between the source files. If used with cp's
55 diff -Nuarp tizen-coreutils/src/cp.c tizen-coreutils-smack/src/cp.c
56 --- tizen-coreutils/src/cp.c 2012-11-30 10:11:38.000000000 +0200
57 +++ tizen-coreutils-smack/src/cp.c 2012-11-30 11:20:39.837516860 +0200
59 #include "stat-time.h"
64 #define ASSIGN_BASENAME_STRDUPA(Dest, File_name) \
66 @@ -191,7 +192,7 @@ Mandatory arguments to long options are
67 -p same as --preserve=mode,ownership,timestamps\n\
68 --preserve[=ATTR_LIST] preserve the specified attributes (default:\n\
69 mode,ownership,timestamps), if possible\n\
70 - additional attributes: links, all\n\
71 + additional attributes: links, context, all\n\
74 --no-preserve=ATTR_LIST don't preserve the specified attributes\n\
75 @@ -317,6 +318,27 @@ re_protect (char const *const_dst_name,
79 + if (x->preserve_context)
81 + char src_context[SMACK_LABELLEN];
82 + char dst_context[SMACK_LABELLEN];
84 + if (smack_of_file (src_name, src_context, SMACK_LABELLEN) < 0 ||
85 + smack_of_file (dst_name, dst_context, SMACK_LABELLEN) < 0)
87 + ; //error (0, errno, _("failed to preserve context for %s"),
88 + // quote (dst_name));
91 + if (strcmp (src_context, dst_context) &&
92 + smack_to_file (dst_name, src_context) < 0)
94 + ; //error (0, errno, _("failed to preserve context for %s"),
95 + // quote (dst_name));
100 if (x->preserve_ownership)
102 if (chown (dst_name, src_sb.st_uid, src_sb.st_gid) != 0
103 @@ -749,6 +771,7 @@ cp_option_init (struct cp_options *x)
104 x->preserve_links = false;
105 x->preserve_mode = false;
106 x->preserve_timestamps = false;
107 + x->preserve_context = false;
109 x->require_preserve = false;
110 x->recursive = false;
111 @@ -777,18 +800,19 @@ decode_preserve_arg (char const *arg, st
118 static enum File_attribute const preserve_vals[] =
120 PRESERVE_MODE, PRESERVE_TIMESTAMPS,
121 - PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_ALL
122 + PRESERVE_OWNERSHIP, PRESERVE_LINK, PRESERVE_CONTEXT, PRESERVE_ALL
124 /* Valid arguments to the `--preserve' option. */
125 static char const* const preserve_args[] =
127 "mode", "timestamps",
128 - "ownership", "links", "all", NULL
129 + "ownership", "links", "context", "all", NULL
131 ARGMATCH_VERIFY (preserve_args, preserve_vals);
133 @@ -824,11 +848,16 @@ decode_preserve_arg (char const *arg, st
134 x->preserve_links = on_off;
137 + case PRESERVE_CONTEXT:
138 + x->preserve_context = on_off;
142 x->preserve_mode = on_off;
143 x->preserve_timestamps = on_off;
144 x->preserve_ownership = on_off;
145 x->preserve_links = on_off;
146 + x->preserve_context = on_off;
150 @@ -885,6 +914,8 @@ main (int argc, char **argv)
151 x.preserve_ownership = true;
152 x.preserve_mode = true;
153 x.preserve_timestamps = true;
154 + /* Context preservation may be draconian */
155 + x.preserve_context = true;
156 x.require_preserve = true;
159 diff -Nuarp tizen-coreutils/src/id.c tizen-coreutils-smack/src/id.c
160 --- tizen-coreutils/src/id.c 2012-11-30 10:11:38.000000000 +0200
161 +++ tizen-coreutils-smack/src/id.c 2012-11-30 11:20:39.837516860 +0200
168 /* The official name of this program (e.g., no `g' prefix). */
169 #define PROGRAM_NAME "id"
170 @@ -40,6 +41,7 @@ int getugroups ();
171 static void print_user (uid_t uid);
172 static void print_group (gid_t gid);
173 static void print_group_list (const char *username);
174 +static void print_context (void);
175 static void print_full_info (const char *username);
177 /* The name this program was run with. */
178 @@ -52,11 +54,15 @@ static bool use_name = false;
179 static uid_t ruid, euid;
180 static gid_t rgid, egid;
182 +/* The security "context" to print. */
183 +static char context[SMACK_LABELLEN];
185 /* True unless errors have been encountered. */
186 static bool ok = true;
188 static struct option const longopts[] =
190 + {"context", no_argument, NULL, 'Z'},
191 {"group", no_argument, NULL, 'g'},
192 {"groups", no_argument, NULL, 'G'},
193 {"name", no_argument, NULL, 'n'},
194 @@ -80,6 +86,7 @@ usage (int status)
195 Print information for USERNAME, or the current user.\n\
197 -a ignore, for compatibility with other versions\n\
198 + -Z, --context print only the security context\n\
199 -g, --group print only the effective group ID\n\
200 -G, --groups print all group IDs\n\
201 -n, --name print a name instead of a number, for -ugG\n\
202 @@ -102,6 +109,8 @@ main (int argc, char **argv)
206 + /* If true, output only the security context. -Z */
207 + bool just_context = false;
208 /* If true, output the list of all group IDs. -G */
209 bool just_group_list = false;
210 /* If true, output only the group ID(s). -g */
211 @@ -119,13 +128,16 @@ main (int argc, char **argv)
213 atexit (close_stdout);
215 - while ((optc = getopt_long (argc, argv, "agnruG", longopts, NULL)) != -1)
216 + while ((optc = getopt_long (argc, argv, "agnruGZ", longopts, NULL)) != -1)
221 /* Ignore -a, for compatibility with SVR4. */
224 + just_context = true;
229 @@ -148,8 +160,8 @@ main (int argc, char **argv)
233 - if (just_user + just_group + just_group_list > 1)
234 - error (EXIT_FAILURE, 0, _("cannot print only user and only group"));
235 + if (just_user + just_group + just_group_list + just_context > 1)
236 + error (EXIT_FAILURE, 0, _("cannot print multiple exclusive fields"));
238 if (just_user + just_group + just_group_list == 0 && (use_real | use_name))
239 error (EXIT_FAILURE, 0,
240 @@ -183,6 +195,8 @@ main (int argc, char **argv)
241 print_group (use_real ? rgid : egid);
242 else if (just_group_list)
243 print_group_list (argv[optind]);
244 + else if (just_context)
247 print_full_info (argv[optind]);
249 @@ -324,6 +338,18 @@ print_group_list (const char *username)
250 #endif /* HAVE_GETGROUPS */
253 +/* Print the security context. */
256 +print_context (void)
259 + if (smack_of_proc(-1, context, sizeof (context)) < 1 || strlen(context) < 1)
260 + printf ("<secuirty context is unavailable>");
262 + printf ("%s", context);
265 /* Print all of the info about the user's user and group IDs. */
268 @@ -385,4 +411,7 @@ print_full_info (const char *username)
271 #endif /* HAVE_GETGROUPS */
273 + if (smack_of_proc(-1, context, sizeof (context)) > 0 && strlen(context) > 0)
274 + printf (" context=\"%s\"", context);
276 diff -Nuarp tizen-coreutils/src/install.c tizen-coreutils-smack/src/install.c
277 --- tizen-coreutils/src/install.c 2012-11-30 10:11:38.000000000 +0200
278 +++ tizen-coreutils-smack/src/install.c 2012-11-30 11:20:39.837516860 +0200
280 #include "stat-time.h"
285 /* The official name of this program (e.g., no `g' prefix). */
286 #define PROGRAM_NAME "install"
287 @@ -115,6 +116,9 @@ static mode_t dir_mode = DEFAULT_MODE;
289 static mode_t dir_mode_bits = CHMOD_MODE_BITS;
291 +/* The security context to give all files. */
292 +static char *context;
294 /* If true, strip executable files after copying them. */
295 static bool strip_files;
297 @@ -124,6 +128,7 @@ static bool dir_arg;
298 static struct option const long_options[] =
300 {"backup", optional_argument, NULL, 'b'},
301 + {"context", required_argument, NULL, 'Z'},
302 {"directory", no_argument, NULL, 'd'},
303 {"group", required_argument, NULL, 'g'},
304 {"mode", required_argument, NULL, 'm'},
305 @@ -155,6 +160,7 @@ cp_option_init (struct cp_options *x)
306 x->preserve_links = false;
307 x->preserve_mode = false;
308 x->preserve_timestamps = false;
309 + x->preserve_context = false;
310 x->require_preserve = false;
311 x->recursive = false;
312 x->sparse_mode = SPARSE_AUTO;
313 @@ -243,7 +249,7 @@ main (int argc, char **argv)
314 we'll actually use backup_suffix_string. */
315 backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
317 - while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pt:TvS:", long_options,
318 + while ((optc = getopt_long (argc, argv, "bcsDdg:m:o:pt:TvS:Z:", long_options,
322 @@ -305,6 +311,9 @@ main (int argc, char **argv)
324 no_target_directory = true;
329 case_GETOPT_HELP_CHAR;
330 case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
332 @@ -520,6 +529,8 @@ change_attributes (char const *name)
333 error (0, errno, _("cannot change ownership of %s"), quote (name));
334 else if (chmod (name, mode) != 0)
335 error (0, errno, _("cannot change permissions of %s"), quote (name));
336 + else if (context && smack_to_file (name, context) < 0)
337 + ; // error (0, errno, _("cannot change security context of %s"), quote (name));
341 @@ -686,6 +697,7 @@ Mandatory arguments to long options are
342 -t, --target-directory=DIRECTORY copy all SOURCE arguments into DIRECTORY\n\
343 -T, --no-target-directory treat DEST as a normal file\n\
344 -v, --verbose print the name of each directory as it is created\n\
345 + -Z, --context=CONTEXT set the security context on all destination files\n\
347 fputs (HELP_OPTION_DESCRIPTION, stdout);
348 fputs (VERSION_OPTION_DESCRIPTION, stdout);
349 diff -Nuarp tizen-coreutils/src/ls.c tizen-coreutils-smack/src/ls.c
350 --- tizen-coreutils/src/ls.c 2012-11-30 10:11:38.000000000 +0200
351 +++ tizen-coreutils-smack/src/ls.c 2012-11-30 11:20:39.841516860 +0200
355 #include "xreadlink.h"
358 #define PROGRAM_NAME (ls_mode == LS_LS ? "ls" \
359 : (ls_mode == LS_MULTI_COL \
360 @@ -177,6 +178,9 @@ struct fileinfo
361 /* For long listings, true if the file has an access control list. */
365 + /* Security context */
366 + char context[SMACK_LABELLEN];
370 @@ -339,6 +343,7 @@ static int nlink_width;
371 static int owner_width;
372 static int group_width;
373 static int author_width;
374 +static int context_width;
375 static int major_device_number_width;
376 static int minor_device_number_width;
377 static int file_size_width;
378 @@ -434,6 +439,10 @@ static bool print_owner = true;
380 static bool print_author;
382 +/* True means to display the security context. */
384 +static bool print_context;
386 /* True means to display group information. -G and -o turn this off. */
388 static bool print_group = true;
389 @@ -1514,7 +1523,7 @@ decode_switches (int argc, char **argv)
392 while ((c = getopt_long (argc, argv,
393 - "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1",
394 + "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
395 long_options, NULL)) != -1)
398 @@ -1717,6 +1726,10 @@ decode_switches (int argc, char **argv)
399 sort_type_specified = true;
403 + print_context = true;
407 /* -1 has no effect after -l. */
408 if (format != long_format)
409 @@ -2574,6 +2587,7 @@ gobble_file (char const *name, enum file
410 /* Command line dereferences are already taken care of by the above
411 assertion that the inode number is not yet known. */
412 || (print_inode && inode == NOT_AN_INODE_NUMBER)
414 || (format_needs_type
415 && (type == unknown || command_line_arg
416 /* --indicator-style=classify (aka -F)
417 @@ -2605,6 +2619,7 @@ gobble_file (char const *name, enum file
421 + err = smack_of_file_follow(absolute_name, f->context, SMACK_LABELLEN);
422 err = stat (absolute_name, &f->stat);
425 @@ -2613,6 +2628,8 @@ gobble_file (char const *name, enum file
426 if (command_line_arg)
429 + err = smack_of_file_follow(absolute_name, f->context,
431 err = stat (absolute_name, &f->stat);
433 if (dereference == DEREF_COMMAND_LINE_ARGUMENTS)
434 @@ -2631,6 +2648,7 @@ gobble_file (char const *name, enum file
437 default: /* DEREF_NEVER */
438 + err = smack_of_file(absolute_name, f->context, SMACK_LABELLEN);
439 err = lstat (absolute_name, &f->stat);
442 @@ -2738,6 +2756,13 @@ gobble_file (char const *name, enum file
448 + int len = strlen (f->context);
449 + if (context_width < len)
450 + context_width = len;
454 char buf[INT_BUFSIZE_BOUND (uintmax_t)];
455 int len = strlen (umaxtostr (f->stat.st_nlink, buf));
456 @@ -3463,7 +3488,7 @@ print_long_format (const struct fileinfo
460 - if (print_owner | print_group | print_author)
461 + if (print_owner | print_group | print_author | print_context)
463 DIRED_FPUTS (buf, stdout, p - buf);
465 @@ -3476,6 +3501,9 @@ print_long_format (const struct fileinfo
467 format_user (f->stat.st_author, author_width, f->stat_ok);
470 + format_user_or_group(f->context, 0, context_width);
475 @@ -3812,6 +3840,9 @@ print_file_name_and_frills (const struct
476 human_readable (ST_NBLOCKS (f->stat), buf, human_output_opts,
477 ST_NBLOCKSIZE, output_block_size));
480 + printf ("%*s ", format == with_commas ? 0 : context_width, f->context);
482 print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
483 f->stat_ok, f->filetype, NULL);
485 @@ -3975,6 +4006,9 @@ length_of_file_name_and_frills (const st
490 + len += 1 + (format == with_commas ? strlen (f->context) : context_width);
492 quote_name (NULL, f->name, filename_quoting_options, &name_width);
495 @@ -4403,6 +4437,7 @@ Mandatory arguments to long options are
496 -w, --width=COLS assume screen width instead of current value\n\
497 -x list entries by lines instead of by columns\n\
498 -X sort alphabetically by entry extension\n\
499 + -Z print the security context\n\
500 -1 list one file per line\n\
502 fputs (HELP_OPTION_DESCRIPTION, stdout);
503 diff -Nuarp tizen-coreutils/src/mkdir.c tizen-coreutils-smack/src/mkdir.c
504 --- tizen-coreutils/src/mkdir.c 2012-11-30 10:11:38.000000000 +0200
505 +++ tizen-coreutils-smack/src/mkdir.c 2012-11-30 11:20:39.841516860 +0200
507 #include "modechange.h"
512 /* The official name of this program (e.g., no `g' prefix). */
513 #define PROGRAM_NAME "mkdir"
514 @@ -40,6 +41,7 @@ char *program_name;
516 static struct option const longopts[] =
518 + {"context", required_argument, NULL, 'Z'},
519 {"mode", required_argument, NULL, 'm'},
520 {"parents", no_argument, NULL, 'p'},
521 {"verbose", no_argument, NULL, 'v'},
522 @@ -65,9 +67,10 @@ Create the DIRECTORY(ies), if they do no
523 Mandatory arguments to long options are mandatory for short options too.\n\
526 - -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n\
527 - -p, --parents no error if existing, make parent directories as needed\n\
528 - -v, --verbose print a message for each created directory\n\
529 + -Z, --context=CONTEXT set security context\n\
530 + -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n\
531 + -p, --parents no error if existing, make parent directories as needed\n\
532 + -v, --verbose print a message for each created directory\n\
534 fputs (HELP_OPTION_DESCRIPTION, stdout);
535 fputs (VERSION_OPTION_DESCRIPTION, stdout);
536 @@ -92,6 +95,9 @@ struct mkdir_options
537 /* File mode bits affected by MODE. */
540 + /* Security context. */
543 /* If not null, format to use when reporting newly made directories. */
544 char const *created_directory_format;
546 @@ -101,6 +107,17 @@ static void
547 announce_mkdir (char const *dir, void *options)
549 struct mkdir_options const *o = options;
552 + char *sep = strrchr(dir, '/');
554 + if ((sep != NULL) && (strlen(sep) != strlen(dir)))
555 + res = smack_to_file (sep + 1, o->context);
557 + res = smack_to_file (dir, o->context);
559 + ; // error (0, errno, _("setting directory context failed"));
561 if (o->created_directory_format)
562 error (0, 0, o->created_directory_format, quote (dir));
564 @@ -144,6 +155,7 @@ main (int argc, char **argv)
565 options.make_ancestor_function = NULL;
566 options.mode = S_IRWXUGO;
567 options.mode_bits = 0;
568 + options.context = NULL;
569 options.created_directory_format = NULL;
571 initialize_main (&argc, &argv);
572 @@ -154,10 +166,13 @@ main (int argc, char **argv)
574 atexit (close_stdout);
576 - while ((optc = getopt_long (argc, argv, "pm:v", longopts, NULL)) != -1)
577 + while ((optc = getopt_long (argc, argv, "Z:pm:v", longopts, NULL)) != -1)
582 + options.context = optarg;
585 options.make_ancestor_function = make_ancestor;
587 diff -Nuarp tizen-coreutils/src/mkfifo.c tizen-coreutils-smack/src/mkfifo.c
588 --- tizen-coreutils/src/mkfifo.c 2012-11-30 10:11:38.000000000 +0200
589 +++ tizen-coreutils-smack/src/mkfifo.c 2012-11-30 11:20:39.841516860 +0200
592 #include "modechange.h"
596 /* The official name of this program (e.g., no `g' prefix). */
597 #define PROGRAM_NAME "mkfifo"
598 @@ -37,6 +38,7 @@ char *program_name;
600 static struct option const longopts[] =
602 + {"context", required_argument, NULL, 'Z'},
603 {"mode", required_argument, NULL, 'm'},
604 {GETOPT_HELP_OPTION_DECL},
605 {GETOPT_VERSION_OPTION_DECL},
606 @@ -60,7 +62,10 @@ Create named pipes (FIFOs) with the give
607 Mandatory arguments to long options are mandatory for short options too.\n\
610 - -m, --mode=MODE set file permission bits to MODE, not a=rw - umask\n\
611 + -Z, --context=CONTEXT set security context to CONTEXT\n\
614 + -m, --mode=MODE set file permission bits to MODE, not a=rw - umask\n\
616 fputs (HELP_OPTION_DESCRIPTION, stdout);
617 fputs (VERSION_OPTION_DESCRIPTION, stdout);
618 @@ -73,6 +78,7 @@ int
619 main (int argc, char **argv)
622 + char const *specified_context = NULL;
623 char const *specified_mode = NULL;
624 int exit_status = EXIT_SUCCESS;
626 @@ -85,10 +91,13 @@ main (int argc, char **argv)
628 atexit (close_stdout);
630 - while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
631 + while ((optc = getopt_long (argc, argv, "Z:m:", longopts, NULL)) != -1)
636 + specified_context = optarg;
639 specified_mode = optarg;
641 @@ -119,11 +128,17 @@ main (int argc, char **argv)
644 for (; optind < argc; ++optind)
645 - if (mkfifo (argv[optind], newmode) != 0)
647 - error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
648 - exit_status = EXIT_FAILURE;
651 + if (mkfifo (argv[optind], newmode) != 0)
653 + error (0, errno, _("cannot create fifo %s"), quote (argv[optind]));
654 + exit_status = EXIT_FAILURE;
656 + if (specified_context &&
657 + smack_to_file(argv[optind], specified_context) < 0)
658 + ;// error (0, errno, _("context assignment of %s to %s failed"),
659 + // argv[optind], quote (specified_context));
664 diff -Nuarp tizen-coreutils/src/mknod.c tizen-coreutils-smack/src/mknod.c
665 --- tizen-coreutils/src/mknod.c 2012-11-30 10:11:38.000000000 +0200
666 +++ tizen-coreutils-smack/src/mknod.c 2012-11-30 11:20:39.841516860 +0200
668 #include "modechange.h"
673 /* The official name of this program (e.g., no `g' prefix). */
674 #define PROGRAM_NAME "mknod"
675 @@ -38,6 +39,7 @@ char *program_name;
677 static struct option const longopts[] =
679 + {"context", required_argument, NULL, 'Z'},
680 {"mode", required_argument, NULL, 'm'},
681 {GETOPT_HELP_OPTION_DECL},
682 {GETOPT_VERSION_OPTION_DECL},
683 @@ -62,7 +64,10 @@ Create the special file NAME of the give
684 Mandatory arguments to long options are mandatory for short options too.\n\
687 - -m, --mode=MODE set file permission bits to MODE, not a=rw - umask\n\
688 + -Z, --context=CONTEXT set file security context to CONTEXT\n\
691 + -m, --mode=MODE set file permission bits to MODE, not a=rw - umask\n\
693 fputs (HELP_OPTION_DESCRIPTION, stdout);
694 fputs (VERSION_OPTION_DESCRIPTION, stdout);
695 @@ -88,6 +93,7 @@ int
696 main (int argc, char **argv)
699 + char const *specified_context = NULL;
700 char const *specified_mode = NULL;
702 int expected_operands;
703 @@ -101,10 +107,13 @@ main (int argc, char **argv)
705 atexit (close_stdout);
707 - while ((optc = getopt_long (argc, argv, "m:", longopts, NULL)) != -1)
708 + while ((optc = getopt_long (argc, argv, "Z:m:", longopts, NULL)) != -1)
713 + specified_context = optarg;
716 specified_mode = optarg;
718 @@ -217,5 +226,9 @@ main (int argc, char **argv)
719 usage (EXIT_FAILURE);
722 + if (specified_context && smack_to_file (argv[optind], specified_context) < 0)
723 + ; //error (0, errno, _("context assignment to %s failed"),
724 + // quote (specified_context));
728 diff -Nuarp tizen-coreutils/src/mv.c tizen-coreutils-smack/src/mv.c
729 --- tizen-coreutils/src/mv.c 2012-11-30 10:11:38.000000000 +0200
730 +++ tizen-coreutils-smack/src/mv.c 2012-11-30 11:20:39.841516860 +0200
732 #include "filenamecat.h"
737 /* The official name of this program (e.g., no `g' prefix). */
738 #define PROGRAM_NAME "mv"
739 @@ -126,6 +127,7 @@ cp_option_init (struct cp_options *x)
740 x->preserve_links = true;
741 x->preserve_mode = true;
742 x->preserve_timestamps = true;
743 + x->preserve_context = true;
744 x->require_preserve = false; /* FIXME: maybe make this an option */
746 x->sparse_mode = SPARSE_AUTO; /* FIXME: maybe make this an option */
747 diff -Nuarp tizen-coreutils/src/smack.h tizen-coreutils-smack/src/smack.h
748 --- tizen-coreutils/src/smack.h 1970-01-01 02:00:00.000000000 +0200
749 +++ tizen-coreutils-smack/src/smack.h 2012-11-30 11:20:39.841516860 +0200
751 +/* smack.h - Simplified Mandatory Access Control Kernel
753 + Copyright (C) 2010 Free Software Foundation, Inc.
755 + This program is free software: you can redistribute it and/or modify
756 + it under the terms of the GNU General Public License as published by
757 + the Free Software Foundation; either version 3 of the License, or
758 + (at your option) any later version.
760 + This program is distributed in the hope that it will be useful,
761 + but WITHOUT ANY WARRANTY; without even the implied warranty of
762 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
763 + GNU General Public License for more details.
765 + You should have received a copy of the GNU General Public License
766 + along with this program. If not, see <http://www.gnu.org/licenses/>.
768 + Written by Casey Schaufler. */
770 +#include <sys/types.h>
771 +#include <sys/stat.h>
772 +#include <sys/xattr.h>
775 +#define SMACK_PATHTEXTSIZE 80
776 +#define SMACK_LABELLEN 256
777 +#define SMACK_PROC_FMT "/proc/%s/attr/current"
778 +#define SMACK_CHECK_PATH "/smack/load"
779 +#define SMACK_ATTRNAME "security.SMACK64"
787 + i = stat(SMACK_CHECK_PATH, &buf);
796 +smack_of_file(const char *path, char *result, int rlen)
800 + i = lgetxattr(path, SMACK_ATTRNAME, result, rlen);
811 +smack_of_file_follow(const char *path, char *result, int rlen)
815 + i = getxattr(path, SMACK_ATTRNAME, result, rlen);
826 +smack_of_fd(int fd, char *result, int rlen)
830 + i = fgetxattr(fd, SMACK_ATTRNAME, result, rlen);
841 +smack_to_fd(int fd, char *smack)
843 + return fsetxattr(fd, SMACK_ATTRNAME, smack, strlen(smack), 0);
847 +smack_to_file(const char *path, char *smack)
849 + return lsetxattr(path, SMACK_ATTRNAME, smack, strlen(smack), 0);
853 +smack_of_proc(pid_t pid, char *result, int rlen)
858 + char pidtext[SMACK_PATHTEXTSIZE];
859 + char path[SMACK_PATHTEXTSIZE];
863 + sprintf(pidtext, "%d", pid);
867 + if (strlen(cp) + strlen(SMACK_PROC_FMT) >= SMACK_PATHTEXTSIZE)
870 + sprintf(path, SMACK_PROC_FMT, cp);
871 + fd = open(path, O_RDONLY);
875 + red = read(fd, result, rlen);
878 + if (red >= 0 && red < rlen)
879 + result[red] = '\0';
880 + if ((cp = index (result, '\n')) != NULL)
883 + return strlen (result);
885 diff -Nuarp tizen-coreutils/src/stat.c tizen-coreutils-smack/src/stat.c
886 --- tizen-coreutils/src/stat.c 2012-11-30 10:11:38.000000000 +0200
887 +++ tizen-coreutils-smack/src/stat.c 2012-11-30 11:20:39.845516860 +0200
889 #include "stat-time.h"
890 #include "strftime.h"
891 #include "xreadlink.h"
894 #define alignof(type) offsetof (struct { char c; type x; }, x)
896 @@ -270,6 +271,8 @@ human_fstype (STRUCT_STATVFS const *stat
898 case S_MAGIC_SYSFS: /* 0x62656572 */
900 + case S_MAGIC_SMACK: /* 0x43415D53 */
905 @@ -595,6 +598,14 @@ print_stat (char *pformat, size_t prefix
907 out_uint (pformat, prefix_len, statbuf->st_ctime);
911 + char context[SMACK_LABELLEN];
913 + if (smack_of_file(filename, context, SMACK_LABELLEN) > 0)
914 + out_string(pformat, prefix_len, context);
920 @@ -855,6 +866,7 @@ The valid format sequences for files (wi
921 %B The size in bytes of each block reported by %b\n\
924 + %C Security context\n\
925 %d Device number in decimal\n\
926 %D Device number in hex\n\
927 %f Raw mode in hex\n\