[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * Mini mkdir implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2001 Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
---|
| 6 | *
|
---|
[1765] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* BB_AUDIT SUSv3 compliant */
|
---|
| 11 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/mkdir.html */
|
---|
| 12 |
|
---|
| 13 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
---|
| 14 | *
|
---|
| 15 | * Fixed broken permission setting when -p was used; especially in
|
---|
| 16 | * conjunction with -m.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
[1765] | 19 | /* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
[821] | 22 | #include <getopt.h> /* struct option */
|
---|
[1765] | 23 | #include "libbb.h"
|
---|
[821] | 24 |
|
---|
[1765] | 25 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 26 |
|
---|
[821] | 27 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
---|
[1765] | 28 | static const char mkdir_longopts[] ALIGN1 =
|
---|
| 29 | "mode\0" Required_argument "m"
|
---|
| 30 | "parents\0" No_argument "p"
|
---|
| 31 | #if ENABLE_SELINUX
|
---|
| 32 | "context\0" Required_argument "Z"
|
---|
[821] | 33 | #endif
|
---|
[1765] | 34 | ;
|
---|
| 35 | #endif
|
---|
[821] | 36 |
|
---|
[1765] | 37 | int mkdir_main(int argc, char **argv);
|
---|
| 38 | int mkdir_main(int argc, char **argv)
|
---|
[821] | 39 | {
|
---|
| 40 | mode_t mode = (mode_t)(-1);
|
---|
| 41 | int status = EXIT_SUCCESS;
|
---|
| 42 | int flags = 0;
|
---|
[1765] | 43 | unsigned opt;
|
---|
[821] | 44 | char *smode;
|
---|
[1765] | 45 | #if ENABLE_SELINUX
|
---|
| 46 | security_context_t scontext;
|
---|
| 47 | #endif
|
---|
[821] | 48 |
|
---|
| 49 | #if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
---|
[1765] | 50 | applet_long_options = mkdir_longopts;
|
---|
[821] | 51 | #endif
|
---|
[1765] | 52 | opt = getopt32(argv, "m:p" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
|
---|
| 53 | if (opt & 1) {
|
---|
| 54 | mode = 0777;
|
---|
| 55 | if (!bb_parse_mode(smode, &mode)) {
|
---|
| 56 | bb_error_msg_and_die("invalid mode '%s'", smode);
|
---|
[821] | 57 | }
|
---|
| 58 | }
|
---|
[1765] | 59 | if (opt & 2)
|
---|
[821] | 60 | flags |= FILEUTILS_RECUR;
|
---|
[1765] | 61 | #if ENABLE_SELINUX
|
---|
| 62 | if (opt & 4) {
|
---|
| 63 | selinux_or_die();
|
---|
| 64 | setfscreatecon_or_die(scontext);
|
---|
| 65 | }
|
---|
| 66 | #endif
|
---|
[821] | 67 |
|
---|
| 68 | if (optind == argc) {
|
---|
| 69 | bb_show_usage();
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | argv += optind;
|
---|
| 73 |
|
---|
| 74 | do {
|
---|
| 75 | if (bb_make_directory(*argv, mode, flags)) {
|
---|
| 76 | status = EXIT_FAILURE;
|
---|
| 77 | }
|
---|
| 78 | } while (*++argv);
|
---|
| 79 |
|
---|
| 80 | return status;
|
---|
| 81 | }
|
---|