mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-16 05:10:03 +01:00
Move tools_write_mk in cryptsetup.
Also drops dependency on lib/utils_io.c in some tools.
This commit is contained in:
committed by
Milan Broz
parent
42692418c2
commit
d6cc88cabb
@@ -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);
|
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)
|
static int action_open_plain(void)
|
||||||
{
|
{
|
||||||
struct crypt_device *cd = NULL, *cd1 = NULL;
|
struct crypt_device *cd = NULL, *cd1 = NULL;
|
||||||
|
|||||||
@@ -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_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
|
||||||
int tools_reencrypt_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_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);
|
int tools_write_json_file(struct crypt_device *cd, const char *file, const char *json);
|
||||||
|
|
||||||
|
|||||||
@@ -29,25 +29,6 @@ void tools_passphrase_msg(int r)
|
|||||||
log_err(_("No usable keyslot is available."));
|
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.
|
* Only tool that currently blocks signals explicitely is cryptsetup-reencrypt.
|
||||||
* Leave the tools_get_key stub with signals handling here and remove it later
|
* Leave the tools_get_key stub with signals handling here and remove it later
|
||||||
|
|||||||
Reference in New Issue
Block a user