Merge lp:~tyhicks/ecryptfs/test-with-xattr-metadata into lp:ecryptfs

Proposed by Tyler Hicks
Status: Merged
Merged at revision: 832
Proposed branch: lp:~tyhicks/ecryptfs/test-with-xattr-metadata
Merge into: lp:ecryptfs
Prerequisite: lp:~tyhicks/ecryptfs/lp1270455
Diff against target: 456 lines (+205/-71)
6 files modified
tests/kernel/lp-509180.sh (+7/-2)
tests/kernel/lp-509180/test.c (+98/-34)
tests/kernel/lp-872905.sh (+5/-3)
tests/kernel/xattr.sh (+6/-1)
tests/kernel/xattr/test.c (+56/-18)
tests/lib/etl_funcs.sh (+33/-13)
To merge this branch: bzr merge lp:~tyhicks/ecryptfs/test-with-xattr-metadata
Reviewer Review Type Date Requested Status
Colin Ian King (community) Approve
Review via email: mp+226557@code.launchpad.net

Description of the change

These patches contain updates to the tests that allow the tests to account for the ecryptfs_xattr_metadata option. Unfortunately, lp-872905.sh still fails on top of ext3. I'll have to look more into that failure.

To post a comment you must log in.
835. By Tyler Hicks

Update the xattr test to do the right thing with or without the
ecryptfs_xattr_metadata mount option.

836. By Tyler Hicks

Update the lp-872905 test to do the right thing with or without the
ecryptfs_xattr_metadata mount option.

Revision history for this message
Tyler Hicks (tyhicks) wrote :

I've pushed another commit, r836, which fixes up the lp-872905.sh test to work with the ecryptfs_xattr_metadata mount option.

Revision history for this message
Colin Ian King (colin-king) wrote :

This looks fine to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/kernel/lp-509180.sh'
2--- tests/kernel/lp-509180.sh 2012-11-02 23:20:18 +0000
3+++ tests/kernel/lp-509180.sh 2014-07-14 07:15:25 +0000
4@@ -22,6 +22,7 @@
5 test_script_dir=$(dirname $0)
6 rc=1
7 test_dir=""
8+xattr_opt=""
9
10 . ${test_script_dir}/../lib/etl_funcs.sh
11
12@@ -48,14 +49,18 @@
13 old_sum=`md5sum $test_dir/test_file | cut -d ' ' -f 1`
14 lower_file=`ls $ETL_MOUNT_SRC/ECRYPTFS*/*`
15
16+if etl_is_mount_opt_set "ecryptfs_xattr_metadata" ; then
17+ xattr_opt="-x"
18+fi
19+
20 # Increment 9th byte so that eCryptfs marker fails validation
21-${test_script_dir}/lp-509180/test -i $lower_file || exit
22+${test_script_dir}/lp-509180/test -i $xattr_opt $lower_file || exit
23 etl_umount
24
25 etl_mount_i || exit
26 cat $test_dir/test_file &> /dev/null
27 # Decrement 9th byte so that eCryptfs marker passes validation
28-${test_script_dir}/lp-509180/test -d $lower_file || exit
29+${test_script_dir}/lp-509180/test -d $xattr_opt $lower_file || exit
30 new_sum=`md5sum $test_dir/test_file | cut -d ' ' -f 1`
31
32 # md5sums should be the same
33
34=== modified file 'tests/kernel/lp-509180/test.c'
35--- tests/kernel/lp-509180/test.c 2013-10-27 16:52:03 +0000
36+++ tests/kernel/lp-509180/test.c 2014-07-14 07:15:25 +0000
37@@ -26,6 +26,7 @@
38 #include <fcntl.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41+#include <attr/xattr.h>
42
43 #define TEST_ERROR (2)
44
45@@ -33,11 +34,98 @@
46
47 #define OPT_INC (0x0001)
48 #define OPT_DEC (0x0002)
49+#define OPT_XATTR (0x0004)
50
51 void usage(char *name)
52 {
53- fprintf(stderr, "Usage: [-i | -d] file\n");
54-}
55+ fprintf(stderr, "Usage: [-i | -d] [-x] file\n");
56+}
57+
58+static int test_with_metadata_in_header(int fd, int flags)
59+{
60+ unsigned char buffer[1];
61+
62+ if ((lseek(fd, (off_t)OFFSET, SEEK_SET)) < 0) {
63+ fprintf(stderr, "Cannot lseek to offset %d: %s\n",
64+ OFFSET, strerror(errno));
65+ return TEST_ERROR;
66+ }
67+
68+ if (read(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
69+ fprintf(stderr, "Failed to read\n");
70+ return TEST_ERROR;
71+ }
72+
73+ if (flags & OPT_INC)
74+ buffer[0]++;
75+
76+ if (flags & OPT_DEC)
77+ buffer[0]--;
78+
79+ if ((lseek(fd, (off_t)OFFSET, SEEK_SET)) < 0) {
80+ fprintf(stderr, "Cannot lseek to offset %d: %s\n",
81+ OFFSET, strerror(errno));
82+ return TEST_ERROR;
83+ }
84+
85+ if (write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
86+ fprintf(stderr, "Failed to write\n");
87+ return TEST_ERROR;
88+ }
89+
90+ return 0;
91+}
92+
93+static int test_with_metadata_in_xattr(int fd, int flags)
94+{
95+ const char *name = "user.ecryptfs";
96+ unsigned char *value = NULL;
97+ size_t nread, size = 0;
98+ int rc = TEST_ERROR;
99+
100+ size = fgetxattr(fd, name, value, size);
101+ if (size < 0) {
102+ fprintf(stderr, "Cannot retrieve xattr size: %s\n",
103+ strerror(errno));
104+ goto out;
105+ }
106+
107+ value = malloc(size);
108+ if (!value) {
109+ fprintf(stderr,
110+ "Cannot allocate memory to store the xattr value\n");
111+ goto out;
112+ }
113+
114+ nread = fgetxattr(fd, name, value, size);
115+ if (nread != size) {
116+ if (nread < 0)
117+ fprintf(stderr, "Cannot read xattr: %s\n",
118+ strerror(errno));
119+ else
120+ fprintf(stderr, "Partial xattr read: %zu < %zu\n",
121+ nread, size);
122+ goto out;
123+ }
124+
125+ if (flags & OPT_INC)
126+ value[OFFSET]++;
127+
128+ if (flags & OPT_DEC)
129+ value[OFFSET]--;
130+
131+ if (fsetxattr(fd, name, value, size, XATTR_REPLACE) < 0) {
132+ fprintf(stderr, "Cannot write xattr: %s\n", strerror(errno));
133+ goto out;
134+ }
135+
136+ rc = 0;
137+out:
138+ free(value);
139+
140+ return rc;
141+}
142+
143
144 /*
145 * https://bugs.launchpad.net/ecryptfs/+bug/509180
146@@ -49,14 +137,13 @@
147 int opt, flags = 0;
148 int rc = 0;
149 char *file;
150- unsigned char buffer[1];
151
152 if (argc < 3) {
153 usage(argv[0]);
154 exit(TEST_ERROR);
155 }
156
157- while ((opt = getopt(argc, argv, "id")) != -1) {
158+ while ((opt = getopt(argc, argv, "idx")) != -1) {
159 switch (opt) {
160 case 'i':
161 flags |= OPT_INC;
162@@ -64,6 +151,9 @@
163 case 'd':
164 flags |= OPT_DEC;
165 break;
166+ case 'x':
167+ flags |= OPT_XATTR;
168+ break;
169 default:
170 usage(argv[0]);
171 exit(TEST_ERROR);
172@@ -82,36 +172,10 @@
173 exit(TEST_ERROR);
174 }
175
176- if ((lseek(fd, (off_t)OFFSET, SEEK_SET)) < 0) {
177- fprintf(stderr, "Cannot lseek to offset %d in %s : %s\n",
178- OFFSET, file, strerror(errno));
179- rc = TEST_ERROR;
180- goto tidy;
181- }
182-
183- if (read(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
184- fprintf(stderr, "Failed to read\n");
185- rc = TEST_ERROR;
186- goto tidy;
187- }
188-
189- if (flags & OPT_INC)
190- buffer[0]++;
191-
192- if (flags & OPT_DEC)
193- buffer[0]--;
194-
195- if ((lseek(fd, (off_t)OFFSET, SEEK_SET)) < 0) {
196- fprintf(stderr, "Cannot lseek to offset %d in %s : %s\n",
197- OFFSET, file, strerror(errno));
198- rc = TEST_ERROR;
199- goto tidy;
200- }
201-
202- if (write(fd, buffer, sizeof(buffer)) != sizeof(buffer)) {
203- fprintf(stderr, "Failed to write\n");
204- rc = TEST_ERROR;
205- }
206+ if (flags & OPT_XATTR)
207+ rc = test_with_metadata_in_xattr(fd, flags);
208+ else
209+ rc = test_with_metadata_in_header(fd, flags);
210
211 tidy:
212 if (close(fd) < 0) {
213
214=== modified file 'tests/kernel/lp-872905.sh'
215--- tests/kernel/lp-872905.sh 2012-11-02 23:20:18 +0000
216+++ tests/kernel/lp-872905.sh 2014-07-14 07:15:25 +0000
217@@ -66,11 +66,13 @@
218 fi
219
220 #
221-# We shouldn't have a lower file created of zero bytes size if
222-# the bug is fixed
223+# If xattr metadata is not enabled, we shouldn't have a zero length lower file.
224+# If xattr metadata is enabled, the expected lower file size is 0.
225 #
226 sz=$(stat -c%s $lower_test_file)
227-if [ $sz -ne 0 ]; then
228+if ! etl_is_mount_opt_set "ecryptfs_xattr_metadata" && [ $sz -ne 0 ]; then
229+ rc=0
230+elif etl_is_mount_opt_set "ecryptfs_xattr_metadata" && [ $sz -eq 0 ]; then
231 rc=0
232 fi
233
234
235=== modified file 'tests/kernel/xattr.sh'
236--- tests/kernel/xattr.sh 2013-01-24 17:33:42 +0000
237+++ tests/kernel/xattr.sh 2014-07-14 07:15:25 +0000
238@@ -23,6 +23,7 @@
239 test_script_dir=$(dirname $0)
240 rc=1
241 test_dir=0
242+xattr_opt=""
243
244 . ${test_script_dir}/../lib/etl_funcs.sh
245
246@@ -45,7 +46,11 @@
247
248 echo "testing 1 2 3" > $test_file
249
250-${test_script_dir}/xattr/test $test_file || exit
251+if etl_is_mount_opt_set "ecryptfs_xattr_metadata" ; then
252+ xattr_opt="-x"
253+fi
254+
255+${test_script_dir}/xattr/test $xattr_opt $test_file || exit
256 rc=$?
257
258 rm -f $test_file1
259
260=== modified file 'tests/kernel/xattr/test.c'
261--- tests/kernel/xattr/test.c 2013-01-24 17:33:42 +0000
262+++ tests/kernel/xattr/test.c 2014-07-14 07:15:25 +0000
263@@ -26,6 +26,8 @@
264 #include <errno.h>
265 #include <sys/xattr.h>
266
267+#define XATTR_METADATA_NAME "user.ecryptfs"
268+
269 static const char *names[] = {
270 "user.test1",
271 "user.test2",
272@@ -40,20 +42,42 @@
273 NULL
274 };
275
276+static void usage(const char *name)
277+{
278+ fprintf(stderr, "Usage: %s [-x] file\n", name);
279+}
280+
281 int main(int argc, char **argv)
282 {
283 ssize_t len, names_len = 0;
284- int i, rc;
285+ int i, rc, xattr_metadata = 0;
286 char buffer[1024];
287- char *ptr = buffer;
288+ char *file, *ptr = buffer;
289
290- if (argc != 2) {
291- fprintf(stderr, "Usage: %s file\n", argv[0]);
292+ if (argc < 2 || argc > 3) {
293+ usage(argv[0]);
294 exit(EXIT_FAILURE);
295 }
296
297+ file = argv[1];
298+
299+ if (argc == 3) {
300+ if (strcmp(argv[1], "-x")) {
301+ usage(argv[0]);
302+ exit(EXIT_FAILURE);
303+ }
304+ file = argv[2];
305+
306+ /*
307+ * The XATTR_METADATA_NAME xattr is set. Account for it in
308+ * future sanity checks.
309+ */
310+ xattr_metadata = 1;
311+ names_len = 1 + strlen(XATTR_METADATA_NAME);
312+ }
313+
314 for (i = 0; names[i]; i++) {
315- if (setxattr(argv[1], names[i], values[i], strlen(values[i]), 0) < 0)
316+ if (setxattr(file, names[i], values[i], strlen(values[i]), 0) < 0)
317 exit(EXIT_FAILURE);
318 names_len += 1 + strlen(names[i]);
319 }
320@@ -61,28 +85,40 @@
321 /*
322 * Sanity check that listxattr returns correct length
323 */
324- len = listxattr(argv[1], NULL, 0);
325+ len = listxattr(file, NULL, 0);
326+ if (len != names_len || len > sizeof(buffer))
327+ exit(EXIT_FAILURE);
328+
329+ len = listxattr(file, buffer, sizeof(buffer));
330 if (len != names_len)
331 exit(EXIT_FAILURE);
332
333- len = listxattr(argv[1], buffer, sizeof(buffer));
334- if (len < 0)
335- exit(EXIT_FAILURE);
336-
337 /*
338 * Check listxattr names match what has been just set
339 */
340- for (i = 0; names[i]; i++) {
341- if (strcmp(names[i], ptr))
342+ for (ptr = buffer; *ptr; ptr += strlen(ptr) + 1) {
343+ int matched = 0;
344+
345+ if (xattr_metadata && !strcmp(XATTR_METADATA_NAME, ptr))
346+ continue;
347+
348+ for (i = 0; names[i]; i++) {
349+ if (strcmp(names[i], ptr))
350+ continue;
351+
352+ matched = 1;
353+ break;
354+ }
355+
356+ if (!matched)
357 exit(EXIT_FAILURE);
358- ptr += strlen(ptr) + 1;
359 }
360
361 /*
362 * Check contents of xattr
363 */
364 for (i = 0; names[i]; i++) {
365- len = getxattr(argv[1], names[i], buffer, sizeof(buffer));
366+ len = getxattr(file, names[i], buffer, sizeof(buffer));
367 if (len < 0)
368 exit(EXIT_FAILURE);
369 buffer[len] = '\0';
370@@ -95,16 +131,18 @@
371 * Remove xattr
372 */
373 for (i = 0; names[i]; i++) {
374- rc = removexattr(argv[1], names[i]);
375+ rc = removexattr(file, names[i]);
376 if (rc < 0)
377 exit(EXIT_FAILURE);
378+ names_len -= 1 + strlen(names[i]);
379 }
380
381 /*
382- * ..and there should be no xattrs left
383+ * ..and the only xattrs that should be left are those that were
384+ * already there when the test started
385 */
386- len = listxattr(argv[1], NULL, 0);
387- if (len != 0)
388+ len = listxattr(file, NULL, 0);
389+ if (len != names_len)
390 exit(EXIT_FAILURE);
391
392 exit(EXIT_SUCCESS);
393
394=== modified file 'tests/lib/etl_funcs.sh'
395--- tests/lib/etl_funcs.sh 2014-07-14 07:15:25 +0000
396+++ tests/lib/etl_funcs.sh 2014-07-14 07:15:25 +0000
397@@ -447,6 +447,38 @@
398 echo $blks
399 }
400
401+_etl_init_mount_opts()
402+{
403+ if [ -z "$ETL_MOUNT_OPTS" ]; then
404+ opts=$default_mount_opts
405+
406+ if [ -n "$ETL_FNEK_SIG" ]; then
407+ opts="$default_fne_mount_opts"
408+ fi
409+
410+ if [ -n "$ETL_APPENDED_MOUNT_OPTS" ]; then
411+ opts="${opts},${ETL_APPENDED_MOUNT_OPTS}"
412+ fi
413+
414+ export ETL_MOUNT_OPTS=$(eval "echo $opts")
415+ fi
416+}
417+
418+etl_is_mount_opt_set()
419+{
420+ if [ -z "$1" ]; then
421+ return 1
422+ fi
423+
424+ _etl_init_mount_opts
425+
426+ if [[ ! $ETL_MOUNT_OPTS =~ (^|,)$1($|,) ]]; then
427+ return 1
428+ fi
429+
430+ return 0
431+}
432+
433 #
434 # etl_mount_i
435 #
436@@ -462,19 +494,7 @@
437 return 1
438 fi
439
440- if [ -z "$ETL_MOUNT_OPTS" ]; then
441- opts=$default_mount_opts
442-
443- if [ -n "$ETL_FNEK_SIG" ]; then
444- opts="$default_fne_mount_opts"
445- fi
446-
447- if [ -n "$ETL_APPENDED_MOUNT_OPTS" ]; then
448- opts="${opts},${ETL_APPENDED_MOUNT_OPTS}"
449- fi
450-
451- export ETL_MOUNT_OPTS=$(eval "echo $opts")
452- fi
453+ _etl_init_mount_opts
454
455 mount -it ecryptfs -o "$ETL_MOUNT_OPTS" \
456 "$ETL_MOUNT_SRC" "$ETL_MOUNT_DST"

Subscribers

People subscribed via source and target branches