Move tools_write_mk in cryptsetup.

Also drops dependency on lib/utils_io.c in some tools.
This commit is contained in:
Ondrej Kozina
2020-07-30 10:18:15 +02:00
committed by Milan Broz
parent 42692418c2
commit d6cc88cabb
3 changed files with 19 additions and 21 deletions

View File

@@ -154,6 +154,25 @@ static int _set_keyslot_encryption_params(struct crypt_device *cd)
return crypt_keyslot_set_encryption(cd, ARG_STR(OPT_KEYSLOT_CIPHER_ID), ARG_UINT32(OPT_KEYSLOT_KEY_SIZE_ID) / 8);
}
static int tools_write_mk(const char *file, const char *key, int keysize)
{
int fd, r = -EINVAL;
fd = open(file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
if (fd < 0) {
log_err(_("Cannot open keyfile %s for write."), file);
return r;
}
if (write_buffer(fd, key, keysize) == keysize)
r = 0;
else
log_err(_("Cannot write to keyfile %s."), file);
close(fd);
return r;
}
static int action_open_plain(void)
{
struct crypt_device *cd = NULL, *cd1 = NULL;

View File

@@ -109,8 +109,6 @@ int tools_is_cipher_null(const char *cipher);
int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
int tools_write_mk(const char *file, const char *key, int keysize);
int tools_read_json_file(struct crypt_device *cd, const char *file, char **json, size_t *json_size);
int tools_write_json_file(struct crypt_device *cd, const char *file, const char *json);

View File

@@ -29,25 +29,6 @@ void tools_passphrase_msg(int r)
log_err(_("No usable keyslot is available."));
}
int tools_write_mk(const char *file, const char *key, int keysize)
{
int fd, r = -EINVAL;
fd = open(file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
if (fd < 0) {
log_err(_("Cannot open keyfile %s for write."), file);
return r;
}
if (write_buffer(fd, key, keysize) == keysize)
r = 0;
else
log_err(_("Cannot write to keyfile %s."), file);
close(fd);
return r;
}
/*
* Only tool that currently blocks signals explicitely is cryptsetup-reencrypt.
* Leave the tools_get_key stub with signals handling here and remove it later