From: Jim Meyering Date: Wed, 31 Jan 2007 22:59:46 +0000 (+0100) Subject: mkdir: Accept new "-Z, --context=C" option. X-Git-Tag: v6.9.89~332 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=301fbaf431677b9be8a7fc279ac1f73d133e7578;p=platform%2Fupstream%2Fcoreutils.git mkdir: Accept new "-Z, --context=C" option. * src/mkdir.c: Include . (main): Honor it. * src/Makefile.am (mkdir_LDADD): Use $(LIB_SELINUX). --- diff --git a/ChangeLog-selinux b/ChangeLog-selinux index 736fd9c..7860f9b 100644 --- a/ChangeLog-selinux +++ b/ChangeLog-selinux @@ -1,5 +1,10 @@ 2007-01-31 Jim Meyering + mkdir: Accept new "-Z, --context=C" option. + * src/mkdir.c: Include . + (main): Honor it. + * src/Makefile.am (mkdir_LDADD): Use $(LIB_SELINUX). + * tests/cp/cp-a-selinux: New file. Test for the bug reported in . * tests/cp/Makefile.am (TESTS): Add cp-a-selinux. diff --git a/src/Makefile.am b/src/Makefile.am index c999c6e..473b7f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -63,6 +63,7 @@ LDADD = ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a chcon_LDADD = $(LDADD) $(LIB_SELINUX) cp_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX) ginstall_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX) +mkdir_LDADD = $(LDADD) $(LIB_SELINUX) mv_LDADD = $(LDADD) $(LIB_EACCESS) $(LIB_SELINUX) pathchk_LDADD = $(LDADD) $(LIB_EACCESS) rm_LDADD = $(LDADD) $(LIB_EACCESS) diff --git a/src/mkdir.c b/src/mkdir.c index 0db7241..b851865 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -1,5 +1,5 @@ /* mkdir -- make directories - Copyright (C) 90, 1995-2002, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 90, 1995-2002, 2004-2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,6 +21,7 @@ #include #include #include +#include #include "system.h" #include "error.h" @@ -40,6 +41,7 @@ char *program_name; static struct option const longopts[] = { + {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, {"mode", required_argument, NULL, 'm'}, {"parents", no_argument, NULL, 'p'}, {"verbose", no_argument, NULL, 'v'}, @@ -68,6 +70,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\ -m, --mode=MODE set file mode (as in chmod), not a=rwx - umask\n\ -p, --parents no error if existing, make parent directories as needed\n\ -v, --verbose print a message for each created directory\n\ + -Z, --context=CTX set the SELinux security context of each created\n\ + directory to CTX\n\ "), stdout); fputs (HELP_OPTION_DESCRIPTION, stdout); fputs (VERSION_OPTION_DESCRIPTION, stdout); @@ -140,7 +144,9 @@ main (int argc, char **argv) { const char *specified_mode = NULL; int optc; + security_context_t scontext = NULL; struct mkdir_options options; + options.make_ancestor_function = NULL; options.mode = S_IRWXUGO; options.mode_bits = 0; @@ -154,7 +160,7 @@ main (int argc, char **argv) atexit (close_stdout); - while ((optc = getopt_long (argc, argv, "pm:v", longopts, NULL)) != -1) + while ((optc = getopt_long (argc, argv, "pm:vZ:", longopts, NULL)) != -1) { switch (optc) { @@ -167,6 +173,9 @@ main (int argc, char **argv) case 'v': /* --verbose */ options.created_directory_format = _("created directory %s"); break; + case 'Z': + scontext = optarg; + break; case_GETOPT_HELP_CHAR; case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); default: @@ -180,6 +189,11 @@ main (int argc, char **argv) usage (EXIT_FAILURE); } + if (scontext && setfscreatecon (scontext) < 0) + error (EXIT_FAILURE, errno, + _("failed to set default file creation context to %s"), + quote (optarg)); + if (options.make_ancestor_function || specified_mode) { mode_t umask_value = umask (0);