"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/test_utils.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.

test_utils.c  (cryptsetup-2.3.6.tar.xz):test_utils.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 44 skipping to change at line 44
# include <sys/syscall.h> # include <sys/syscall.h>
#endif #endif
#ifdef HAVE_SYS_SYSMACROS_H #ifdef HAVE_SYS_SYSMACROS_H
# include <sys/sysmacros.h> # include <sys/sysmacros.h>
#endif #endif
#include <linux/loop.h> #include <linux/loop.h>
#include "api_test.h" #include "api_test.h"
#include "libcryptsetup.h" #include "libcryptsetup.h"
#ifndef LOOP_CONFIGURE
#define LOOP_CONFIGURE 0x4C0A
struct loop_config {
__u32 fd;
__u32 block_size;
struct loop_info64 info;
__u64 __reserved[8];
};
#endif
static char last_error[256]; static char last_error[256];
static char global_log[4096]; static char global_log[4096];
static uint32_t t_dm_crypt_flags = 0; static uint32_t t_dm_crypt_flags = 0;
char *THE_LOOP_DEV = NULL; char *THE_LOOP_DEV = NULL;
int _debug = 0; int _debug = 0;
int global_lines = 0; int global_lines = 0;
int _quit = 0; int _quit = 0;
int _verbose = 0; int _verbose = 0;
uint64_t t_dev_offset = 0; uint64_t t_dev_offset = 0;
skipping to change at line 276 skipping to change at line 286
if (endp != &buffer[2]) if (endp != &buffer[2])
return -1; return -1;
} }
if (*hex != '\0') if (*hex != '\0')
return -1; return -1;
return 0; return 0;
} }
void global_log_callback(int level, const char *msg, void *usrptr) void global_log_callback(int level, const char *msg, void *usrptr __attribute__( (unused)))
{ {
size_t len; size_t len;
if (_debug) { if (_debug) {
if (level == CRYPT_LOG_DEBUG) if (level == CRYPT_LOG_DEBUG)
fprintf(stdout, "# %s", msg); fprintf(stdout, "# %s", msg);
else else
fprintf(stdout, "%s", msg); fprintf(stdout, "%s", msg);
} }
skipping to change at line 325 skipping to change at line 335
int _system(const char *command, int warn) int _system(const char *command, int warn)
{ {
int r; int r;
if (_debug) if (_debug)
printf("Running system: %s\n", command); printf("Running system: %s\n", command);
if ((r=system(command)) < 0 && warn) if ((r=system(command)) < 0 && warn)
printf("System command failed: %s", command); printf("System command failed: %s", command);
return r; return r;
} }
static int keyring_check(void) static int _keyring_check(void)
{ {
#ifdef KERNEL_KEYRING #ifdef KERNEL_KEYRING
return syscall(__NR_request_key, "logon", "dummy", NULL, 0) == -1l && err no != ENOSYS; return syscall(__NR_request_key, "logon", "dummy", NULL, 0) == -1l && err no != ENOSYS;
#else #else
return 0; return 0;
#endif #endif
} }
static int t_dm_satisfies_version(unsigned target_maj, unsigned target_min, unsi gned target_patch, static int t_dm_satisfies_version(unsigned target_maj, unsigned target_min, unsi gned target_patch,
unsigned actual_maj, unsigned actual_min, unsign ed actual_patch) unsigned actual_maj, unsigned actual_min, unsign ed actual_patch)
skipping to change at line 380 skipping to change at line 390
t_dm_crypt_flags |= T_DM_DISCARDS_SUPPORTED; t_dm_crypt_flags |= T_DM_DISCARDS_SUPPORTED;
if (t_dm_satisfies_version(1, 13, 0, crypt_maj, crypt_min, 0)) if (t_dm_satisfies_version(1, 13, 0, crypt_maj, crypt_min, 0))
t_dm_crypt_flags |= T_DM_TCW_SUPPORTED; t_dm_crypt_flags |= T_DM_TCW_SUPPORTED;
if (t_dm_satisfies_version(1, 14, 0, crypt_maj, crypt_min, 0)) { if (t_dm_satisfies_version(1, 14, 0, crypt_maj, crypt_min, 0)) {
t_dm_crypt_flags |= T_DM_SAME_CPU_CRYPT_SUPPORTED; t_dm_crypt_flags |= T_DM_SAME_CPU_CRYPT_SUPPORTED;
t_dm_crypt_flags |= T_DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED; t_dm_crypt_flags |= T_DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED;
} }
if (t_dm_satisfies_version(1, 18, 1, crypt_maj, crypt_min, crypt_patch) & & keyring_check()) if (t_dm_satisfies_version(1, 18, 1, crypt_maj, crypt_min, crypt_patch) & & _keyring_check())
t_dm_crypt_flags |= T_DM_KERNEL_KEYRING_SUPPORTED; t_dm_crypt_flags |= T_DM_KERNEL_KEYRING_SUPPORTED;
} }
static void t_dm_set_verity_compat(const char *dm_version, unsigned verity_maj, static void t_dm_set_verity_compat(const char *dm_version __attribute__((unused)
unsigned verity_min, unsigned verity_patch) ),
unsigned verity_maj,
unsigned verity_min,
unsigned verity_patch __attribute__((unused)))
{ {
if (verity_maj > 0) if (verity_maj > 0)
t_dm_crypt_flags |= T_DM_VERITY_SUPPORTED; t_dm_crypt_flags |= T_DM_VERITY_SUPPORTED;
else else
return; return;
/* /*
* ignore_corruption, restart_on corruption is available since 1.2 (kerne l 4.1) * ignore_corruption, restart_on corruption is available since 1.2 (kerne l 4.1)
* ignore_zero_blocks since 1.3 (kernel 4.5) * ignore_zero_blocks since 1.3 (kernel 4.5)
* (but some dm-verity targets 1.2 don't support it) * (but some dm-verity targets 1.2 don't support it)
* FEC is added in 1.3 as well. * FEC is added in 1.3 as well.
*/ */
if (t_dm_satisfies_version(1, 3, 0, verity_maj, verity_min, 0)) { if (t_dm_satisfies_version(1, 3, 0, verity_maj, verity_min, 0)) {
t_dm_crypt_flags |= T_DM_VERITY_ON_CORRUPTION_SUPPORTED; t_dm_crypt_flags |= T_DM_VERITY_ON_CORRUPTION_SUPPORTED;
t_dm_crypt_flags |= T_DM_VERITY_FEC_SUPPORTED; t_dm_crypt_flags |= T_DM_VERITY_FEC_SUPPORTED;
} }
} }
static void t_dm_set_integrity_compat(const char *dm_version, unsigned integrity static void t_dm_set_integrity_compat(const char *dm_version __attribute__((unus
_maj, ed)),
unsigned integrity_min, unsigned integrity_ unsigned integrity_maj __attribute__((unused)),
patch) unsigned integrity_min __attribute__((unused)),
unsigned integrity_patch __attribute__((unused)))
{ {
if (integrity_maj > 0) if (integrity_maj > 0)
t_dm_crypt_flags |= T_DM_INTEGRITY_SUPPORTED; t_dm_crypt_flags |= T_DM_INTEGRITY_SUPPORTED;
} }
int t_dm_check_versions(void) int t_dm_check_versions(void)
{ {
struct dm_task *dmt; struct dm_task *dmt;
struct dm_versions *target, *last_target; struct dm_versions *target, *last_target;
char dm_version[16]; char dm_version[16];
skipping to change at line 555 skipping to change at line 569
if (stat(dev, &st) || !S_ISBLK(st.st_mode)) if (stat(dev, &st) || !S_ISBLK(st.st_mode))
return NULL; return NULL;
return strdup(dev); return strdup(dev);
} }
int loop_attach(char **loop, const char *file, int offset, int loop_attach(char **loop, const char *file, int offset,
int autoclear, int *readonly) int autoclear, int *readonly)
{ {
struct loop_info64 lo64 = {0}; struct loop_config config = {0};
char *lo_file_name; char *lo_file_name;
int loop_fd = -1, file_fd = -1, r = 1; int loop_fd = -1, file_fd = -1, r = 1;
int fallback = 0;
*loop = NULL; *loop = NULL;
file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL); file_fd = open(file, (*readonly ? O_RDONLY : O_RDWR) | O_EXCL);
if (file_fd < 0 && (errno == EROFS || errno == EACCES) && !*readonly) { if (file_fd < 0 && (errno == EROFS || errno == EACCES) && !*readonly) {
*readonly = 1; *readonly = 1;
file_fd = open(file, O_RDONLY | O_EXCL); file_fd = open(file, O_RDONLY | O_EXCL);
} }
if (file_fd < 0) if (file_fd < 0)
goto out; goto out;
config.fd = file_fd;
lo_file_name = (char*)config.info.lo_file_name;
lo_file_name[LO_NAME_SIZE-1] = '\0';
strncpy(lo_file_name, file, LO_NAME_SIZE-1);
config.info.lo_offset = offset;
if (autoclear)
config.info.lo_flags |= LO_FLAGS_AUTOCLEAR;
while (loop_fd < 0) { while (loop_fd < 0) {
*loop = crypt_loop_get_device(); *loop = crypt_loop_get_device();
if (!*loop) if (!*loop)
goto out; goto out;
loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR); loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
if (loop_fd < 0) if (loop_fd < 0)
goto out; goto out;
if (ioctl(loop_fd, LOOP_CONFIGURE, &config) < 0) {
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) { if (errno == EINVAL || errno == ENOTTY) {
free(*loop);
*loop = NULL;
close(loop_fd);
loop_fd = -1;
/* kernel doesn't support LOOP_CONFIGURE */
fallback = 1;
break;
}
if (errno != EBUSY) if (errno != EBUSY)
goto out; goto out;
free(*loop); free(*loop);
*loop = NULL; *loop = NULL;
close(loop_fd); close(loop_fd);
loop_fd = -1; loop_fd = -1;
} }
} }
lo_file_name = (char*)lo64.lo_file_name; if (fallback)
lo_file_name[LO_NAME_SIZE-1] = '\0'; {
strncpy(lo_file_name, file, LO_NAME_SIZE-1); while (loop_fd < 0) {
lo64.lo_offset = offset; *loop = crypt_loop_get_device();
if (autoclear) if (!*loop)
lo64.lo_flags |= LO_FLAGS_AUTOCLEAR; goto out;
if (ioctl(loop_fd, LOOP_SET_STATUS64, &lo64) < 0) { loop_fd = open(*loop, *readonly ? O_RDONLY : O_RDWR);
(void)ioctl(loop_fd, LOOP_CLR_FD, 0); if (loop_fd < 0)
goto out; goto out;
if (ioctl(loop_fd, LOOP_SET_FD, file_fd) < 0) {
if (errno != EBUSY)
goto out;
free(*loop);
*loop = NULL;
close(loop_fd);
loop_fd = -1;
}
}
if (ioctl(loop_fd, LOOP_SET_STATUS64, &config.info) < 0) {
(void)ioctl(loop_fd, LOOP_CLR_FD, 0);
goto out;
}
} }
/* Verify that autoclear is really set */ /* Verify that autoclear is really set */
if (autoclear) { if (autoclear) {
memset(&lo64, 0, sizeof(lo64)); memset(&config.info, 0, sizeof(config.info));
if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0 || if (ioctl(loop_fd, LOOP_GET_STATUS64, &config.info) < 0 ||
!(lo64.lo_flags & LO_FLAGS_AUTOCLEAR)) { !(config.info.lo_flags & LO_FLAGS_AUTOCLEAR)) {
(void)ioctl(loop_fd, LOOP_CLR_FD, 0); (void)ioctl(loop_fd, LOOP_CLR_FD, 0);
goto out; goto out;
} }
} }
r = 0; r = 0;
out: out:
if (r && loop_fd >= 0) if (r && loop_fd >= 0)
close(loop_fd); close(loop_fd);
if (file_fd >= 0) if (file_fd >= 0)
 End of changes. 13 change blocks. 
24 lines changed or deleted 73 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)