| Line | Source | Count | 
|---|
| 1 |  | - | 
| 2 |  | - | 
| 3 |  | - | 
| 4 |  | - | 
| 5 |  | - | 
| 6 |  | - | 
| 7 |  | - | 
| 8 |  | - | 
| 9 |  | - | 
| 10 |  | - | 
| 11 |  | - | 
| 12 |  | - | 
| 13 |  | - | 
| 14 |  | - | 
| 15 |  | - | 
| 16 |  | - | 
| 17 |  | - | 
| 18 |  | - | 
| 19 |  | - | 
| 20 |  | - | 
| 21 | #include <config.h> | - | 
| 22 |  | - | 
| 23 | #include "mkdir-p.h" | - | 
| 24 |  | - | 
| 25 | #include <errno.h> | - | 
| 26 | #include <sys/stat.h> | - | 
| 27 | #include <unistd.h> | - | 
| 28 |  | - | 
| 29 | #include "gettext.h" | - | 
| 30 | #define _(msgid) gettext (msgid) | - | 
| 31 |  | - | 
| 32 | #include "dirchownmod.h" | - | 
| 33 | #include "dirname.h" | - | 
| 34 | #include "error.h" | - | 
| 35 | #include "quote.h" | - | 
| 36 | #include "mkancesdirs.h" | - | 
| 37 | #include "savewd.h" | - | 
| 38 |  | - | 
| 39 | #ifndef HAVE_FCHMOD | - | 
| 40 | # define HAVE_FCHMOD false | - | 
| 41 | #endif | - | 
| 42 |  | - | 
| 43 |  | - | 
| 44 |  | - | 
| 45 |  | - | 
| 46 |  | - | 
| 47 |  | - | 
| 48 |  | - | 
| 49 |  | - | 
| 50 |  | - | 
| 51 |  | - | 
| 52 |  | - | 
| 53 |  | - | 
| 54 |  | - | 
| 55 |  | - | 
| 56 |  | - | 
| 57 |  | - | 
| 58 |  | - | 
| 59 |  | - | 
| 60 |  | - | 
| 61 |  | - | 
| 62 |  | - | 
| 63 |  | - | 
| 64 |  | - | 
| 65 |  | - | 
| 66 |  | - | 
| 67 |  | - | 
| 68 |  | - | 
| 69 |  | - | 
| 70 |  | - | 
| 71 |  | - | 
| 72 |  | - | 
| 73 |  | - | 
| 74 |  | - | 
| 75 |  | - | 
| 76 |  | - | 
| 77 |  | - | 
| 78 |  | - | 
| 79 |  | - | 
| 80 |  | - | 
| 81 |  | - | 
| 82 |  | - | 
| 83 |  | - | 
| 84 | bool | - | 
| 85 | make_dir_parents (char *dir, | - | 
| 86 | struct savewd *wd, | - | 
| 87 | int (*make_ancestor) (char const *, char const *, void *), | - | 
| 88 | void *options, | - | 
| 89 | mode_t mode, | - | 
| 90 | void (*announce) (char const *, void *), | - | 
| 91 | mode_t mode_bits, | - | 
| 92 | uid_t owner, | - | 
| 93 | gid_t group, | - | 
| 94 | bool preserve_existing) | - | 
| 95 | { | - | 
| 96 | int mkdir_errno = (IS_ABSOLUTE_FILE_NAME (dir) ? 0 : savewd_errno (wd)); | TRUE | evaluated 2 times by 1 test |  | FALSE | evaluated 10279 times by 2 tests | 
| TRUE | never evaluated |  | FALSE | evaluated 10279 times by 2 tests | 
 | 0-10279 | 
| 97 |  | - | 
| 98 | if (mkdir_errno == 0) | TRUE | evaluated 10281 times by 2 tests |  | FALSE | never evaluated | 
 | 0-10281 | 
| 99 | { | - | 
| 100 | ptrdiff_t prefix_len = 0; | - | 
| 101 | int savewd_chdir_options = (HAVE_FCHMOD ? SAVEWD_CHDIR_SKIP_READABLE : 0); dead code: 0 | - | 
| 102 |  | - | 
| 103 | if (make_ancestor) | TRUE | evaluated 123 times by 2 tests |  | FALSE | evaluated 10158 times by 1 test | 
 | 123-10158 | 
| 104 | { | - | 
| 105 | prefix_len = mkancesdirs (dir, wd, make_ancestor, options); | - | 
| 106 | if (prefix_len < 0) | TRUE | evaluated 5 times by 1 test |  | FALSE | evaluated 118 times by 2 tests | 
 | 5-118 | 
| 107 | { | - | 
| 108 | if (prefix_len < -1) | TRUE | evaluated 4 times by 1 test |  | FALSE | evaluated 1 time by 1 test | 
 | 1-4 | 
| 109 | return true; executed 4 times by 1 test:  return 1 ; | 4 | 
| 110 | mkdir_errno = errno; | - | 
| 111 | } executed 1 time by 1 test:  end of block | 1 | 
| 112 | } executed 119 times by 2 tests:  end of block | 119 | 
| 113 |  | - | 
| 114 | if (0 <= prefix_len) | TRUE | evaluated 10276 times by 2 tests |  | FALSE | evaluated 1 time by 1 test | 
 | 1-10276 | 
| 115 | { | - | 
| 116 |  | - | 
| 117 |  | - | 
| 118 |  | - | 
| 119 |  | - | 
| 120 |  | - | 
| 121 | bool keep_owner = owner == (uid_t) -1 && group == (gid_t) -1; | TRUE | evaluated 10276 times by 2 tests |  | FALSE | never evaluated | 
| TRUE | evaluated 10276 times by 2 tests |  | FALSE | never evaluated | 
 | 0-10276 | 
| 122 | bool keep_special_mode_bits = | - | 
| 123 | ((mode_bits & (S_ISUID | S_ISGID)) | (mode & S_ISVTX)) == 0; | - | 
| 124 | mode_t mkdir_mode = mode; | - | 
| 125 | if (! keep_owner) | TRUE | never evaluated |  | FALSE | evaluated 10276 times by 2 tests | 
 | 0-10276 | 
| 126 | mkdir_mode &= ~ (S_IRWXG | S_IRWXO); never executed: mkdir_mode &= ~ ( ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3) ); | 0 | 
| 127 | else if (! keep_special_mode_bits) | TRUE | evaluated 8 times by 1 test |  | FALSE | evaluated 10268 times by 1 test | 
 | 8-10268 | 
| 128 | mkdir_mode &= ~ (S_IWGRP | S_IWOTH); executed 8 times by 1 test:  mkdir_mode &= ~ ( (0200 >> 3) | ((0200 >> 3) >> 3) ); | 8 | 
| 129 |  | - | 
| 130 | if (mkdir (dir + prefix_len, mkdir_mode) == 0) | TRUE | evaluated 10273 times by 2 tests |  | FALSE | evaluated 3 times by 1 test | 
 | 3-10273 | 
| 131 | { | - | 
| 132 |  | - | 
| 133 |  | - | 
| 134 | bool umask_must_be_ok = (mode & mode_bits & S_IRWXUGO) == 0; | - | 
| 135 |  | - | 
| 136 | announce (dir, options); | - | 
| 137 | preserve_existing = (keep_owner & keep_special_mode_bits | - | 
| 138 | & umask_must_be_ok); | - | 
| 139 | savewd_chdir_options |= SAVEWD_CHDIR_NOFOLLOW; | - | 
| 140 | } executed 10273 times by 2 tests:  end of block | 10273 | 
| 141 | else | - | 
| 142 | { | - | 
| 143 | mkdir_errno = errno; | - | 
| 144 | mkdir_mode = -1; | - | 
| 145 | } executed 3 times by 1 test:  end of block | 3 | 
| 146 |  | - | 
| 147 | if (preserve_existing) | TRUE | evaluated 10267 times by 1 test |  | FALSE | evaluated 9 times by 2 tests | 
 | 9-10267 | 
| 148 | { | - | 
| 149 | struct stat st; | - | 
| 150 | if (mkdir_errno == 0 | TRUE | evaluated 10267 times by 1 test |  | FALSE | never evaluated | 
 | 0-10267 | 
| 151 | || (mkdir_errno != ENOENT && make_ancestor | TRUE | never evaluated |  | FALSE | never evaluated | 
| TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 152 | && stat (dir + prefix_len, &st) == 0 | TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 153 | && S_ISDIR (st.st_mode))) | TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 154 | return true; executed 10267 times by 1 test:  return 1 ; | 10267 | 
| 155 | } never executed: end of block | 0 | 
| 156 | else | - | 
| 157 | { | - | 
| 158 | int open_result[2]; | - | 
| 159 | int chdir_result = | - | 
| 160 | savewd_chdir (wd, dir + prefix_len, | - | 
| 161 | savewd_chdir_options, open_result); | - | 
| 162 | if (chdir_result < -1) | TRUE | never evaluated |  | FALSE | evaluated 9 times by 2 tests | 
 | 0-9 | 
| 163 | return true; never executed: return 1 ; | 0 | 
| 164 | else | - | 
| 165 | { | - | 
| 166 | bool chdir_ok = (chdir_result == 0); | - | 
| 167 | char const *subdir = (chdir_ok ? "." : dir + prefix_len); | TRUE | evaluated 9 times by 2 tests |  | FALSE | never evaluated | 
 | 0-9 | 
| 168 | if (dirchownmod (open_result[0], subdir, mkdir_mode, | TRUE | evaluated 9 times by 2 tests |  | FALSE | never evaluated | 
 | 0-9 | 
| 169 | owner, group, mode, mode_bits) | TRUE | evaluated 9 times by 2 tests |  | FALSE | never evaluated | 
 | 0-9 | 
| 170 | == 0) | TRUE | evaluated 9 times by 2 tests |  | FALSE | never evaluated | 
 | 0-9 | 
| 171 | return true; executed 9 times by 2 tests:  return 1 ; | 9 | 
| 172 |  | - | 
| 173 | if (mkdir_errno == 0 | TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 174 | || (mkdir_errno != ENOENT && make_ancestor | TRUE | never evaluated |  | FALSE | never evaluated | 
| TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 175 | && errno != ENOTDIR)) | TRUE | never evaluated |  | FALSE | never evaluated | 
 | 0 | 
| 176 | { | - | 
| 177 | error (0, errno, | - | 
| 178 | _(keep_owner | - | 
| 179 | ? "cannot change permissions of %s" | - | 
| 180 | : "cannot change owner and permissions of %s"), | - | 
| 181 | quote (dir)); | - | 
| 182 | return false; never executed: return 0 ; | 0 | 
| 183 | } | - | 
| 184 | } never executed: end of block | 0 | 
| 185 | } | - | 
| 186 | } | - | 
| 187 | } executed 1 time by 1 test:  end of block | 1 | 
| 188 |  | - | 
| 189 | error (0, mkdir_errno, _("cannot create directory %s"), quote (dir)); | - | 
| 190 | return false; executed 1 time by 1 test:  return 0 ; | 1 | 
| 191 | } | - | 
|  |  |  |