summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-01-31 23:59:46 +0100
committerJim Meyering <jim@meyering.net>2007-03-29 21:37:06 +0200
commit301fbaf431677b9be8a7fc279ac1f73d133e7578 (patch)
tree9e9df6c0e002349ff730bc23d7e4e813a6211b17 /src
parent8a86223d45be7597b229a95381aebab3512bf6d7 (diff)
downloadcoreutils-301fbaf431677b9be8a7fc279ac1f73d133e7578.tar.xz
mkdir: Accept new "-Z, --context=C" option.
* src/mkdir.c: Include <selinux/selinux.h>. (main): Honor it. * src/Makefile.am (mkdir_LDADD): Use $(LIB_SELINUX).
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/mkdir.c18
2 files changed, 17 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c999c6e1b..473b7f7d0 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 0db72415e..b85186540 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 <stdio.h>
#include <getopt.h>
#include <sys/types.h>
+#include <selinux/selinux.h>
#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);