Add options parameters to tools_wipe_all_signatures routine.

This commit is contained in:
Ondrej Kozina
2022-06-16 15:50:23 +02:00
parent 369a18cd3b
commit 4892b24d6a
4 changed files with 11 additions and 7 deletions

View File

@@ -1372,7 +1372,7 @@ int luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_password
} }
/* Signature candidates found */ /* Signature candidates found */
if (signatures && ((r = tools_wipe_all_signatures(header_device)) < 0)) if (signatures && ((r = tools_wipe_all_signatures(header_device, true, false)) < 0))
goto out; goto out;
if (ARG_SET(OPT_INTEGRITY_LEGACY_PADDING_ID)) if (ARG_SET(OPT_INTEGRITY_LEGACY_PADDING_ID))
@@ -1392,7 +1392,7 @@ int luksFormat(struct crypt_device **r_cd, char **r_password, size_t *r_password
key, keysize, key, keysize,
password, passwordLen); password, passwordLen);
if (r < 0) { if (r < 0) {
(void) tools_wipe_all_signatures(header_device); (void) tools_wipe_all_signatures(header_device, true, false);
goto out; goto out;
} }
tools_keyslot_msg(r, CREATED); tools_keyslot_msg(r, CREATED);

View File

@@ -118,7 +118,7 @@ typedef enum {
} tools_probe_filter_info; } tools_probe_filter_info;
int tools_detect_signatures(const char *device, tools_probe_filter_info filter, size_t *count, bool batch_mode); int tools_detect_signatures(const char *device, tools_probe_filter_info filter, size_t *count, bool batch_mode);
int tools_wipe_all_signatures(const char *path); int tools_wipe_all_signatures(const char *path, bool exclusive, bool only_luks);
int tools_superblock_block_size(const char *device, char *sb_name, int tools_superblock_block_size(const char *device, char *sb_name,
size_t sb_name_len, unsigned *r_block_size); size_t sb_name_len, unsigned *r_block_size);
bool tools_blkid_supported(void); bool tools_blkid_supported(void);

View File

@@ -195,7 +195,7 @@ static int action_format(void)
goto out; goto out;
/* Signature candidates found */ /* Signature candidates found */
if (signatures && ((r = tools_wipe_all_signatures(action_argv[0])) < 0)) if (signatures && ((r = tools_wipe_all_signatures(action_argv[0], true, false)) < 0))
goto out; goto out;
if (ARG_SET(OPT_INTEGRITY_LEGACY_PADDING_ID)) if (ARG_SET(OPT_INTEGRITY_LEGACY_PADDING_ID))

View File

@@ -258,7 +258,7 @@ out:
return r; return r;
} }
int tools_wipe_all_signatures(const char *path) int tools_wipe_all_signatures(const char *path, bool exclusive, bool only_luks)
{ {
int fd, flags, r; int fd, flags, r;
blk_probe_status pr; blk_probe_status pr;
@@ -276,7 +276,7 @@ int tools_wipe_all_signatures(const char *path)
} }
flags = O_RDWR; flags = O_RDWR;
if (S_ISBLK(st.st_mode)) if (S_ISBLK(st.st_mode) && exclusive)
flags |= O_EXCL; flags |= O_EXCL;
/* better than opening regular file with O_EXCL (undefined) */ /* better than opening regular file with O_EXCL (undefined) */
@@ -284,7 +284,7 @@ int tools_wipe_all_signatures(const char *path)
fd = open(path, flags); /* lgtm[cpp/toctou-race-condition] */ fd = open(path, flags); /* lgtm[cpp/toctou-race-condition] */
if (fd < 0) { if (fd < 0) {
if (errno == EBUSY) if (errno == EBUSY)
log_err(_("Device %s is in use. Cannot proceed with format operation."), path); log_err(_("Cannot exclusively open %s, device in use."), path);
else else
log_err(_("Failed to open file %s in read/write mode."), path); log_err(_("Failed to open file %s in read/write mode."), path);
return -EINVAL; return -EINVAL;
@@ -297,6 +297,10 @@ int tools_wipe_all_signatures(const char *path)
} }
blk_set_chains_for_wipes(h); blk_set_chains_for_wipes(h);
if (only_luks && (r = blk_superblocks_only_luks(h))) {
r = -EINVAL;
goto out;
}
while ((pr = blk_probe(h)) < PRB_EMPTY) { while ((pr = blk_probe(h)) < PRB_EMPTY) {
if (blk_is_partition(h)) if (blk_is_partition(h))