"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 237ae42 | 2002-11-03 14:05:15 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 237ae42 | 2002-11-03 14:05:15 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 6 | #include "libbb.h" |
Denys Vlasenko | d184a72 | 2011-09-22 12:45:14 +0200 | [diff] [blame] | 7 | #include "bb_archive.h" |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 8 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 9 | void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 10 | { |
| 11 | file_header_t *file_header = archive_handle->file_header; |
| 12 | int dst_fd; |
| 13 | int res; |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 14 | char *hard_link; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 15 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
| 16 | char *dst_name; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 17 | #else |
| 18 | # define dst_name (file_header->name) |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 19 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 20 | |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 21 | #if ENABLE_FEATURE_TAR_SELINUX |
Denys Vlasenko | 6111f96 | 2012-02-23 13:45:18 +0100 | [diff] [blame] | 22 | char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE]; |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 23 | if (!sctx) |
Denys Vlasenko | 6111f96 | 2012-02-23 13:45:18 +0100 | [diff] [blame] | 24 | sctx = archive_handle->tar__sctx[PAX_GLOBAL]; |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 25 | if (sctx) { /* setfscreatecon is 4 syscalls, avoid if possible */ |
| 26 | setfscreatecon(sctx); |
Denys Vlasenko | 6111f96 | 2012-02-23 13:45:18 +0100 | [diff] [blame] | 27 | free(archive_handle->tar__sctx[PAX_NEXT_FILE]); |
| 28 | archive_handle->tar__sctx[PAX_NEXT_FILE] = NULL; |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 29 | } |
| 30 | #endif |
| 31 | |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 32 | /* Hard links are encoded as regular files of size 0 |
| 33 | * with a nonempty link field */ |
| 34 | hard_link = NULL; |
| 35 | if (S_ISREG(file_header->mode) && file_header->size == 0) |
| 36 | hard_link = file_header->link_target; |
| 37 | |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 38 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
| 39 | dst_name = file_header->name; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 40 | if (archive_handle->tar__strip_components) { |
| 41 | unsigned n = archive_handle->tar__strip_components; |
| 42 | do { |
| 43 | dst_name = strchr(dst_name, '/'); |
| 44 | if (!dst_name || dst_name[1] == '\0') { |
| 45 | data_skip(archive_handle); |
Denys Vlasenko | 537389c | 2015-10-22 13:38:09 +0200 | [diff] [blame] | 46 | goto ret; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 47 | } |
| 48 | dst_name++; |
| 49 | /* |
| 50 | * Link target is shortened only for hardlinks: |
| 51 | * softlinks restored unchanged. |
| 52 | */ |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 53 | if (hard_link) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 54 | // GNU tar 1.26 does not check that we reached end of link name: |
| 55 | // if "dir/hardlink" is hardlinked to "file", |
| 56 | // tar xvf a.tar --strip-components=1 says: |
| 57 | // tar: hardlink: Cannot hard link to '': No such file or directory |
| 58 | // and continues processing. We silently skip such entries. |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 59 | hard_link = strchr(hard_link, '/'); |
| 60 | if (!hard_link || hard_link[1] == '\0') { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 61 | data_skip(archive_handle); |
Denys Vlasenko | 537389c | 2015-10-22 13:38:09 +0200 | [diff] [blame] | 62 | goto ret; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 63 | } |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 64 | hard_link++; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 65 | } |
| 66 | } while (--n != 0); |
| 67 | } |
| 68 | #endif |
| 69 | |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 70 | if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 71 | char *slash = strrchr(dst_name, '/'); |
Denys Vlasenko | f94c9bf | 2009-11-29 07:45:33 +0100 | [diff] [blame] | 72 | if (slash) { |
| 73 | *slash = '\0'; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 74 | bb_make_directory(dst_name, -1, FILEUTILS_RECUR); |
Denys Vlasenko | f94c9bf | 2009-11-29 07:45:33 +0100 | [diff] [blame] | 75 | *slash = '/'; |
| 76 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 77 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 78 | |
Denys Vlasenko | d57d626 | 2009-09-17 02:43:14 +0200 | [diff] [blame] | 79 | if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) { |
Denis Vlasenko | 1af00ed | 2008-04-05 02:44:30 +0000 | [diff] [blame] | 80 | /* Remove the entry if it exists */ |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 81 | if (!S_ISDIR(file_header->mode)) { |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 82 | if (hard_link) { |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 83 | /* Ugly special case: |
| 84 | * tar cf t.tar hardlink1 hardlink2 hardlink1 |
| 85 | * results in this tarball structure: |
| 86 | * hardlink1 |
| 87 | * hardlink2 -> hardlink1 |
| 88 | * hardlink1 -> hardlink1 <== !!! |
| 89 | */ |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 90 | if (strcmp(hard_link, dst_name) == 0) |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 91 | goto ret; |
| 92 | } |
| 93 | /* Proceed with deleting */ |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 94 | if (unlink(dst_name) == -1 |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 95 | && errno != ENOENT |
| 96 | ) { |
| 97 | bb_perror_msg_and_die("can't remove old file %s", |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 98 | dst_name); |
Denys Vlasenko | 02365a6 | 2010-04-09 10:52:52 +0200 | [diff] [blame] | 99 | } |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
Denis Vlasenko | a60936d | 2008-06-28 05:04:09 +0000 | [diff] [blame] | 102 | else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) { |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 103 | /* Remove the existing entry if its older than the extracted entry */ |
Denys Vlasenko | 6ccaa23 | 2009-11-24 01:16:12 +0100 | [diff] [blame] | 104 | struct stat existing_sb; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 105 | if (lstat(dst_name, &existing_sb) == -1) { |
Glenn L McGrath | 8dc8cb1 | 2003-11-15 23:44:31 +0000 | [diff] [blame] | 106 | if (errno != ENOENT) { |
Denys Vlasenko | d57d626 | 2009-09-17 02:43:14 +0200 | [diff] [blame] | 107 | bb_perror_msg_and_die("can't stat old file"); |
Glenn L McGrath | 8dc8cb1 | 2003-11-15 23:44:31 +0000 | [diff] [blame] | 108 | } |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 109 | } |
Denys Vlasenko | 6ccaa23 | 2009-11-24 01:16:12 +0100 | [diff] [blame] | 110 | else if (existing_sb.st_mtime >= file_header->mtime) { |
Pascal Bellard | 873bb31 | 2010-10-18 00:54:51 +0200 | [diff] [blame] | 111 | if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) |
| 112 | && !S_ISDIR(file_header->mode) |
| 113 | ) { |
Denis Vlasenko | cba9ef5 | 2006-10-10 21:00:47 +0000 | [diff] [blame] | 114 | bb_error_msg("%s not created: newer or " |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 115 | "same age file exists", dst_name); |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 116 | } |
| 117 | data_skip(archive_handle); |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 118 | goto ret; |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 119 | } |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 120 | else if ((unlink(dst_name) == -1) && (errno != EISDIR)) { |
Denys Vlasenko | d57d626 | 2009-09-17 02:43:14 +0200 | [diff] [blame] | 121 | bb_perror_msg_and_die("can't remove old file %s", |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 122 | dst_name); |
Glenn L McGrath | 4cee66d | 2003-08-28 19:12:23 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Denys Vlasenko | f167e45 | 2015-10-22 13:30:34 +0200 | [diff] [blame] | 126 | /* Handle hard links separately */ |
| 127 | if (hard_link) { |
| 128 | res = link(hard_link, dst_name); |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 129 | if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) { |
Denys Vlasenko | 06f20bf | 2017-01-26 00:27:53 +0100 | [diff] [blame] | 130 | /* shared message */ |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 131 | bb_perror_msg("can't create %slink '%s' to '%s'", |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame^] | 132 | "hard", dst_name, hard_link |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 133 | ); |
Glenn L McGrath | 3d5828f | 2003-08-14 02:55:15 +0000 | [diff] [blame] | 134 | } |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 135 | /* Hardlinks have no separate mode/ownership, skip chown/chmod */ |
| 136 | goto ret; |
| 137 | } |
| 138 | |
| 139 | /* Create the filesystem entry */ |
| 140 | switch (file_header->mode & S_IFMT) { |
| 141 | case S_IFREG: { |
| 142 | /* Regular file */ |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 143 | char *dst_nameN; |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 144 | int flags = O_WRONLY | O_CREAT | O_EXCL; |
| 145 | if (archive_handle->ah_flags & ARCHIVE_O_TRUNC) |
| 146 | flags = O_WRONLY | O_CREAT | O_TRUNC; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 147 | dst_nameN = dst_name; |
Denys Vlasenko | 2aec773 | 2013-02-20 15:58:42 +0100 | [diff] [blame] | 148 | #ifdef ARCHIVE_REPLACE_VIA_RENAME |
| 149 | if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) |
| 150 | /* rpm-style temp file name */ |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 151 | dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid()); |
Denys Vlasenko | 2aec773 | 2013-02-20 15:58:42 +0100 | [diff] [blame] | 152 | #endif |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 153 | dst_fd = xopen3(dst_nameN, |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 154 | flags, |
| 155 | file_header->mode |
| 156 | ); |
| 157 | bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size); |
| 158 | close(dst_fd); |
Denys Vlasenko | 2aec773 | 2013-02-20 15:58:42 +0100 | [diff] [blame] | 159 | #ifdef ARCHIVE_REPLACE_VIA_RENAME |
| 160 | if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 161 | xrename(dst_nameN, dst_name); |
| 162 | free(dst_nameN); |
Denys Vlasenko | 2aec773 | 2013-02-20 15:58:42 +0100 | [diff] [blame] | 163 | } |
| 164 | #endif |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 165 | break; |
| 166 | } |
| 167 | case S_IFDIR: |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 168 | res = mkdir(dst_name, file_header->mode); |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 169 | if ((res == -1) |
| 170 | && (errno != EISDIR) /* btw, Linux doesn't return this */ |
| 171 | && (errno != EEXIST) |
| 172 | && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) |
| 173 | ) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 174 | bb_perror_msg("can't make dir %s", dst_name); |
Denis Vlasenko | 714701c | 2006-12-22 00:21:07 +0000 | [diff] [blame] | 175 | } |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 176 | break; |
| 177 | case S_IFLNK: |
| 178 | /* Symlink */ |
Denys Vlasenko | 243d175 | 2010-07-04 04:26:55 +0200 | [diff] [blame] | 179 | //TODO: what if file_header->link_target == NULL (say, corrupted tarball?) |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 180 | |
| 181 | /* To avoid a directory traversal attack via symlinks, |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame^] | 182 | * do not restore symlinks with ".." components |
| 183 | * or symlinks starting with "/", unless a magic |
| 184 | * envvar is set. |
Denys Vlasenko | b920a38 | 2017-07-24 17:20:13 +0200 | [diff] [blame] | 185 | * |
| 186 | * For example, consider a .tar created via: |
| 187 | * $ tar cvf bug.tar anything.txt |
| 188 | * $ ln -s /tmp symlink |
| 189 | * $ tar --append -f bug.tar symlink |
| 190 | * $ rm symlink |
| 191 | * $ mkdir symlink |
| 192 | * $ tar --append -f bug.tar symlink/evil.py |
| 193 | * |
| 194 | * This will result in an archive that contains: |
| 195 | * $ tar --list -f bug.tar |
| 196 | * anything.txt |
| 197 | * symlink [-> /tmp] |
| 198 | * symlink/evil.py |
| 199 | * |
| 200 | * Untarring bug.tar would otherwise place evil.py in '/tmp'. |
| 201 | */ |
Denys Vlasenko | bc9bbeb | 2017-08-10 11:52:42 +0200 | [diff] [blame^] | 202 | if (!unsafe_symlink_target(file_header->link_target)) { |
| 203 | res = symlink(file_header->link_target, dst_name); |
| 204 | if (res != 0 |
| 205 | && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) |
| 206 | ) { |
| 207 | /* shared message */ |
| 208 | bb_perror_msg("can't create %slink '%s' to '%s'", |
| 209 | "sym", |
| 210 | dst_name, file_header->link_target |
| 211 | ); |
| 212 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 213 | } |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 214 | break; |
| 215 | case S_IFSOCK: |
| 216 | case S_IFBLK: |
| 217 | case S_IFCHR: |
| 218 | case S_IFIFO: |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 219 | res = mknod(dst_name, file_header->mode, file_header->device); |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 220 | if ((res == -1) |
| 221 | && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) |
| 222 | ) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 223 | bb_perror_msg("can't create node %s", dst_name); |
Denys Vlasenko | e69ad87 | 2010-04-09 14:11:45 +0200 | [diff] [blame] | 224 | } |
| 225 | break; |
| 226 | default: |
| 227 | bb_error_msg_and_die("unrecognized file type"); |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 230 | if (!S_ISLNK(file_header->mode)) { |
| 231 | if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_OWNER)) { |
Denis Vlasenko | 8b814b4 | 2009-04-21 00:52:21 +0000 | [diff] [blame] | 232 | uid_t uid = file_header->uid; |
| 233 | gid_t gid = file_header->gid; |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 234 | #if ENABLE_FEATURE_TAR_UNAME_GNAME |
| 235 | if (!(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) { |
| 236 | if (file_header->tar__uname) { |
Denys Vlasenko | f94c9bf | 2009-11-29 07:45:33 +0100 | [diff] [blame] | 237 | //TODO: cache last name/id pair? |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 238 | struct passwd *pwd = getpwnam(file_header->tar__uname); |
| 239 | if (pwd) uid = pwd->pw_uid; |
| 240 | } |
| 241 | if (file_header->tar__gname) { |
| 242 | struct group *grp = getgrnam(file_header->tar__gname); |
| 243 | if (grp) gid = grp->gr_gid; |
| 244 | } |
Denis Vlasenko | 8b814b4 | 2009-04-21 00:52:21 +0000 | [diff] [blame] | 245 | } |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 246 | #endif |
Denys Vlasenko | f94c9bf | 2009-11-29 07:45:33 +0100 | [diff] [blame] | 247 | /* GNU tar 1.15.1 uses chown, not lchown */ |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 248 | chown(dst_name, uid, gid); |
Denys Vlasenko | d86b4c3 | 2010-06-18 02:00:55 +0200 | [diff] [blame] | 249 | } |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 250 | /* uclibc has no lchmod, glibc is even stranger - |
| 251 | * it has lchmod which seems to do nothing! |
| 252 | * so we use chmod... */ |
Denys Vlasenko | d57d626 | 2009-09-17 02:43:14 +0200 | [diff] [blame] | 253 | if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) { |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 254 | chmod(dst_name, file_header->mode); |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 255 | } |
Denys Vlasenko | d57d626 | 2009-09-17 02:43:14 +0200 | [diff] [blame] | 256 | if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) { |
Denys Vlasenko | dcbfaba | 2009-11-29 19:40:36 +0100 | [diff] [blame] | 257 | struct timeval t[2]; |
Denys Vlasenko | 389cca4 | 2009-11-15 02:28:56 +0100 | [diff] [blame] | 258 | |
Denys Vlasenko | dcbfaba | 2009-11-29 19:40:36 +0100 | [diff] [blame] | 259 | t[1].tv_sec = t[0].tv_sec = file_header->mtime; |
| 260 | t[1].tv_usec = t[0].tv_usec = 0; |
Denys Vlasenko | 6c563e3 | 2015-10-22 01:07:13 +0200 | [diff] [blame] | 261 | utimes(dst_name, t); |
Denis Vlasenko | 7510384 | 2007-06-20 14:49:47 +0000 | [diff] [blame] | 262 | } |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 263 | } |
J. Tang | 77a2c51 | 2010-03-19 14:48:51 +0100 | [diff] [blame] | 264 | |
| 265 | ret: ; |
| 266 | #if ENABLE_FEATURE_TAR_SELINUX |
| 267 | if (sctx) { |
| 268 | /* reset the context after creating an entry */ |
| 269 | setfscreatecon(NULL); |
| 270 | } |
| 271 | #endif |
Glenn L McGrath | 7ca04f3 | 2002-09-25 02:47:48 +0000 | [diff] [blame] | 272 | } |