From 17bc43cb82320f2aba4ccb804bd8599232524c6a Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 28 Jun 2013 13:27:42 +0200 Subject: trust: Implement reloading of token data * Reload token data whenever a new session is opened. * Only reload files/directories that have changed. * Move duplicate anchor/blacklist detection logic into the extract code. This is in line with the approach being discussed on the mailing lists and spec document. * New internal attribute CKA_X_ORIGIN set on all objects so we can track where an object came from, and replace it when reloaded. In general this is a prerequisite for modification of objects reload before modify is necessary to prevent multiple callers clobbering each other's changes. --- trust/tests/test-trust.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'trust/tests/test-trust.c') diff --git a/trust/tests/test-trust.c b/trust/tests/test-trust.c index 33ba19e..fceaea7 100644 --- a/trust/tests/test-trust.c +++ b/trust/tests/test-trust.c @@ -324,3 +324,78 @@ test_check_directory_msg (const char *file, p11_dict_free (files); } + +void +test_write_file_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name, + const void *contents, + size_t length) +{ + char *path; + FILE *f; + + if (asprintf (&path, "%s/%s", directory, name) < 0) + assert_not_reached (); + + f = fopen (path, "wb"); + if (f == NULL) { + p11_test_fail (file, line, function, "Couldn't open file for writing: %s: %s", + path, strerror (errno)); + } + + if (fwrite (contents, 1, length, f) != length || + fclose (f) != 0) { + p11_test_fail (file, line, function, "Couldn't write file: %s: %s", + path, strerror (errno)); + } + + free (path); +} + +void +test_delete_file_msg (const char *file, + int line, + const char *function, + const char *directory, + const char *name) +{ + char *path; + + if (asprintf (&path, "%s/%s", directory, name) < 0) + assert_not_reached (); + + if (unlink (path) < 0) + p11_test_fail (file, line, function, "Couldn't delete file: %s", path); + + free (path); +} + +void +test_delete_directory_msg (const char *file, + int line, + const char *function, + const char *directory) +{ + struct dirent *dp; + DIR *dir; + + dir = opendir (directory); + if (dir == NULL) + p11_test_fail (file ,line, function, "Couldn't open directory: %s", directory); + + while ((dp = readdir (dir)) != NULL) { + if (strcmp (dp->d_name, ".") == 0 || + strcmp (dp->d_name, "..") == 0) + continue; + + test_delete_file_msg (file, line, function, directory, dp->d_name); + } + + closedir (dir); + + if (rmdir (directory) < 0) + p11_test_fail (file, line, function, "Couldn't remove directory: %s", directory); +} -- cgit v1.1