aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-core/swupd-client/swupd-client/0007-Add-compatibility-with-libarchive-s-bsdtar-command.patch
blob: 6d03ee3794e4f5432996f890de30ce737ed647fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
From 29e2fefaf67bfd6db77db87d22782a31c7284982 Mon Sep 17 00:00:00 2001
From: Dmitry Rozhkov <dmitry.rozhkov@intel.com>
Date: Mon, 8 Feb 2016 16:42:23 +0200
Subject: [PATCH] Add compatibility with libarchive's bsdtar command

Since GNU tar fails to extract files with xattrs preserved when
Integrity Measurement Architecture (IMA) is enabled some vendors
may choose to install libarchive-based tar (bsdtar) on their embedded
devices, so the swupd server needs to be able to create archives
in its format.

This patch adds one compile-time options --enable-bsdtar that is used
to enable/disable GNU tar specific options.

Upstream-Status: Accepted

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
 configure.ac                  |  9 +++++++++
 include/swupd-build-variant.h | 12 ++++++++++--
 src/download.c                |  4 ++--
 src/esp.c                     |  4 ++--
 src/manifest.c                |  3 ++-
 src/packs.c                   |  2 +-
 src/staging.c                 | 12 ++++++------
 7 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/configure.ac b/configure.ac
index b11ef0a..930f64c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,6 +29,15 @@ AS_IF([test "x$enable_bzip2" = "xyes" ],
   [AC_DEFINE(SWUPD_WITHOUT_BZIP2,1,[Do not use bzip2 compression])]
 )
 
+AC_ARG_ENABLE(
+	[bsdtar],
+	AS_HELP_STRING([--enable-bsdtar], [Use alternative bsdtar command (uses tar by default)])
+)
+AS_IF([test "x$enable_bsdtar" = "xyes" ],
+	[AC_DEFINE(SWUPD_WITH_BSDTAR, 1, [Use bsdtar])],
+    [AC_DEFINE(SWUPD_WITHOUT_BSDTAR, 1, [Use default tar])]
+)
+
 AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR],
             [path to systemd system service dir @<:@default=/usr/lib/systemd/system@:>@]), [unitpath=${withval}],
             [unitpath="$($PKG_CONFIG --variable=systemdsystemunitdir systemd)"])
diff --git a/include/swupd-build-variant.h b/include/swupd-build-variant.h
index f2103a2..0c15dca 100644
--- a/include/swupd-build-variant.h
+++ b/include/swupd-build-variant.h
@@ -13,10 +13,18 @@
 #define VERIFY_FAILED_MAX_VERSIONS_COUNT 20
 #endif
 
+#ifdef SWUPD_WITH_BSDTAR
+#define TAR_COMMAND "bsdtar"
+#define TAR_XATTR_ARGS ""
+#else
+#define TAR_COMMAND "tar"
+#define TAR_XATTR_ARGS "--xattrs --xattrs-include='*'"
+#endif
+
 #ifdef SWUPD_WITH_SELINUX
-#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*' --selinux"
+#define TAR_PERM_ATTR_ARGS "--preserve-permissions --selinux " TAR_XATTR_ARGS
 #else /* SWUPD_WITHOUT_SELINUX */
-#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*'"
+#define TAR_PERM_ATTR_ARGS "--preserve-permissions " TAR_XATTR_ARGS
 #endif
 
 #ifdef SWUPD_WITH_REPAIR
diff --git a/src/download.c b/src/download.c
index cb6d1a2..211ee24 100644
--- a/src/download.c
+++ b/src/download.c
@@ -194,7 +194,7 @@ static int check_tarfile_content(struct file *file, const char *tarfilename)
 	int count = 0;
 
 	/* we're using -a because the server side has a choice between different compression methods */
-	string_or_die(&tarcommand, "tar -tf %s/download/%s.tar 2> /dev/null", STATE_DIR, file->hash);
+	string_or_die(&tarcommand, TAR_COMMAND " -tf %s/download/%s.tar 2> /dev/null", STATE_DIR, file->hash);
 
 	err = access(tarfilename, R_OK);
 	if (err) {
@@ -300,7 +300,7 @@ static void untar_full_download(void *data)
 	}
 
 	/* modern tar will automatically determine the compression type used */
-	string_or_die(&tarcommand, "tar -C %s/staged/ " TAR_PERM_ATTR_ARGS " -xf %s 2> /dev/null",
+	string_or_die(&tarcommand, TAR_COMMAND " -C %s/staged/ " TAR_PERM_ATTR_ARGS " -xf %s 2> /dev/null",
 			STATE_DIR, tarfile);
 
 	LOG_DEBUG(file, "Doing tar operation", class_file_compression, "%s", tarcommand);
diff --git a/src/esp.c b/src/esp.c
index e2b2ae9..3483f55 100644
--- a/src/esp.c
+++ b/src/esp.c
@@ -231,8 +231,8 @@ int copy_files_to_esp(int target_version)
 
 	progress_step(PROGRESS_MSG_UPDATE_ESP);
 
-	string_or_die(&tarcommand, "tar -C %s/%d/system/vendor/intel/ -cf - esp 2> /dev/null | "
-				  "tar -C %s/ -xf - --no-same-permissions --no-same-owner --transform=\"s/esp//\" 2> /dev/null",
+	string_or_die(&tarcommand, TAR_COMMAND " -C %s/%d/system/vendor/intel/ -cf - esp 2> /dev/null | "
+				  TAR_COMMAND " -C %s/ -xf - --no-same-permissions --no-same-owner --transform=\"s/esp//\" 2> /dev/null",
 				  MOUNT_POINT, target_version, ESP_MOUNT);
 
 	ret = system(tarcommand);
diff --git a/src/manifest.c b/src/manifest.c
index 5757e9f..7c356d7 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 
 #include "config.h"
+#include "swupd-build-variant.h"
 #include <swupd.h>
 #include <xattrs.h>
 #include "progress.h"
@@ -519,7 +520,7 @@ static int retrieve_manifests(int current, int version, char *component, struct
 		goto out;
 	}
 
-	string_or_die(&tar, "tar -C %s/%i -xf %s/%i/Manifest.%s.tar 2> /dev/null",
+	string_or_die(&tar, TAR_COMMAND " -C %s/%i -xf %s/%i/Manifest.%s.tar 2> /dev/null",
 			STATE_DIR, version, STATE_DIR, version, component);
 
 	LOG_DEBUG(NULL, "tar", class_file_compression, "running %s", tar);
diff --git a/src/packs.c b/src/packs.c
index b176b74..91a83c5 100644
--- a/src/packs.c
+++ b/src/packs.c
@@ -83,7 +83,7 @@ static int download_pack(int oldversion, int newversion, char *module)
 	free(url);
 
 	progress_step(PROGRESS_MSG_EXTRACTING_PACK);
-	string_or_die(&tar, "tar -C %s " TAR_PERM_ATTR_ARGS " -xf %s/pack-%s-from-%i-to-%i.tar 2> /dev/null",
+	string_or_die(&tar, TAR_COMMAND " -C %s " TAR_PERM_ATTR_ARGS " -xf %s/pack-%s-from-%i-to-%i.tar 2> /dev/null",
 			STATE_DIR, STATE_DIR, module, oldversion, newversion);
 
 	LOG_INFO(NULL, "Untar of delta pack", class_file_compression, "%s", tar);
diff --git a/src/staging.c b/src/staging.c
index 16dafbb..742e8a2 100644
--- a/src/staging.c
+++ b/src/staging.c
@@ -402,8 +402,8 @@ int do_staging(struct file *file)
 			ret = -errno;
 			goto out;
 		}
-		string_or_die(&tarcommand, "tar -C %s " TAR_PERM_ATTR_ARGS " -cf - %s 2> /dev/null | "
-			"tar -C %s%s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
+		string_or_die(&tarcommand, TAR_COMMAND " -C %s " TAR_PERM_ATTR_ARGS " -cf - %s 2> /dev/null | "
+			TAR_COMMAND " -C %s%s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
 			rename_tmpdir, base, path_prefix, rel_dir);
 		LOG_DEBUG(file, "directory overwrite", class_osvol_staging, "%s", tarcommand);
 		ret = system(tarcommand);
@@ -440,8 +440,8 @@ int do_staging(struct file *file)
 				ret = -errno;
 				goto out;
 			}
-			string_or_die(&tarcommand, "tar -C %s/staged " TAR_PERM_ATTR_ARGS " -cf - .update.%s 2> /dev/null | "
-				"tar -C %s%s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
+			string_or_die(&tarcommand, TAR_COMMAND " -C %s/staged " TAR_PERM_ATTR_ARGS " -cf - .update.%s 2> /dev/null | "
+				TAR_COMMAND " -C %s%s " TAR_PERM_ATTR_ARGS " -xf - 2> /dev/null",
 				STATE_DIR, base, path_prefix, rel_dir);
 			LOG_DEBUG(file, "dotfile install", class_osvol_staging, "%s", tarcommand);
 			ret = system(tarcommand);
@@ -485,8 +485,8 @@ int do_staging(struct file *file)
 	/* For initial simplicity replace the file.  Ideally this would be
 	 * an intelligent btrfs reflink to maximize block level reuse. */
 	//TODO: prove btrfs reflink ioctl works in general, then try using them here
-	string_or_die(&tarcommand, "tar -C %s/staged " TAR_PERM_ATTR_ARGS " -cf - %s 2> /dev/null | "
-		"tar -C %s/%s " TAR_PERM_ATTR_ARGS " -xf - --transform=\"s/%s/%s/\" 2> /dev/null",
+	string_or_die(&tarcommand, TAR_COMMAND " -C %s/staged " TAR_PERM_ATTR_ARGS " -cf - %s 2> /dev/null | "
+		TAR_COMMAND " -C %s/%s " TAR_PERM_ATTR_ARGS " -xf - --transform=\"s/%s/%s/\" 2> /dev/null",
 		STATE_DIR, file->hash, STAGING_SUBVOL, rel_dir, file->hash, base);
 	ret = system(tarcommand);
 	free(tarcommand);
-- 
2.5.0