+2009-11-14 Milan Broz <mbroz@redhat.com>
+ * Add CRYPT_ prefix to enum defined in libcryptsetup.h.
+
2009-09-30 Milan Broz <mbroz@redhat.com>
* Fix exported symbols and versions in libcryptsetup.
* Do not use internal lib functions in cryptsetup.
* @cd - crypt device handle, can be NULL
* @name -crypt device name
*
- * INACTIVE - no such mapped device
- * ACTIVE - device is active
- * BUSY - device is active and has open count > 0
- */
-typedef enum { INVALID, INACTIVE, ACTIVE, BUSY } crypt_status_info;
+ * CRYPT_INACTIVE - no such mapped device
+ * CRYPT_ACTIVE - device is active
+ * CRYPT_BUSY - device is active and has open count > 0
+ */
+typedef enum {
+ CRYPT_INVALID,
+ CRYPT_INACTIVE,
+ CRYPT_ACTIVE,
+ CRYPT_BUSY
+} crypt_status_info;
crypt_status_info crypt_status(struct crypt_device *cd, const char *name);
/**
* @cd - crypt device handle
* @keyslot - requested keyslot to check or CRYPT_ANY_SLOT
*/
-typedef enum { SLOT_INVALID, SLOT_INACTIVE, SLOT_ACTIVE, SLOT_ACTIVE_LAST } crypt_keyslot_info;
+typedef enum {
+ CRYPT_SLOT_INVALID,
+ CRYPT_SLOT_INACTIVE,
+ CRYPT_SLOT_ACTIVE,
+ CRYPT_SLOT_ACTIVE_LAST
+} crypt_keyslot_info;
crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot);
/**
}
switch (LUKS_keyslot_info(&cd->hdr, *keyslot)) {
- case SLOT_INVALID:
+ case CRYPT_SLOT_INVALID:
log_err(cd, _("Key slot %d is invalid, please select between 0 and %d.\n"),
*keyslot, LUKS_NUMKEYS - 1);
return -EINVAL;
- case SLOT_INACTIVE:
+ case CRYPT_SLOT_INACTIVE:
break;
default:
log_err(cd, _("Key slot %d is full, please select another one.\n"),
return -EINVAL;
ki = crypt_keyslot_status(cd, keyIndex);
- if (ki == SLOT_ACTIVE) /* Not last slot */
+ if (ki == CRYPT_SLOT_ACTIVE) /* Not last slot */
LUKS_keyslot_set(&cd->hdr, keyIndex, 0);
openedIndex = LUKS_open_key_with_hdr(cd->device, CRYPT_ANY_SLOT,
password, passwordLen,
&cd->hdr, &mk, cd);
- if (ki == SLOT_ACTIVE)
+ if (ki == CRYPT_SLOT_ACTIVE)
LUKS_keyslot_set(&cd->hdr, keyIndex, 1);
LUKS_dealloc_masterkey(mk);
safe_free(password);
}
ki = crypt_keyslot_status(cd, key_slot);
- if (ki == SLOT_INVALID) {
+ if (ki == CRYPT_SLOT_INVALID) {
log_err(cd, _("Key slot %d is invalid, please select between 0 and %d.\n"),
key_slot, LUKS_NUMKEYS - 1);
r = -EINVAL;
goto out;
}
- if (ki <= SLOT_INACTIVE) {
+ if (ki <= CRYPT_SLOT_INACTIVE) {
log_err(cd, _("Key %d not active. Can't wipe.\n"), key_slot);
r = -EINVAL;
goto out;
}
- if (ki == SLOT_ACTIVE_LAST && cd->confirm &&
+ if (ki == CRYPT_SLOT_ACTIVE_LAST && cd->confirm &&
!(cd->confirm(_("This is the last keyslot."
" Device will become unusable after purging this key."),
cd->confirm_usrptr))) {
int r;
ci = crypt_status(cd, name);
- if (ci == INVALID)
+ if (ci == CRYPT_INVALID)
return -EINVAL;
- if (reload && ci < ACTIVE)
+ if (reload && ci < CRYPT_ACTIVE)
return -EINVAL;
- if (!reload && ci >= ACTIVE) {
+ if (!reload && ci >= CRYPT_ACTIVE) {
log_err(cd, _("Device %s already exists.\n"), name);
return -EEXIST;
}
log_dbg("Allocating crypt device context by device %s.", name);
ci = crypt_status(NULL, name);
- if (ci == INVALID)
+ if (ci == CRYPT_INVALID)
return -ENODEV;
- if (ci < ACTIVE) {
+ if (ci < CRYPT_ACTIVE) {
log_err(NULL, _("Device %s is not active.\n"), name);
return -ENODEV;
}
log_dbg("Suspending volume %s.", name);
ci = crypt_status(NULL, name);
- if (ci < ACTIVE) {
+ if (ci < CRYPT_ACTIVE) {
log_err(cd, _("Volume %s is not active.\n"), name);
return -EINVAL;
}
}
ki = crypt_keyslot_status(cd, keyslot);
- if (ki == SLOT_INVALID) {
+ if (ki == CRYPT_SLOT_INVALID) {
log_err(cd, _("Key slot %d is invalid.\n"), keyslot);
return -EINVAL;
}
- if (ki == SLOT_INACTIVE) {
+ if (ki == CRYPT_SLOT_INACTIVE) {
log_err(cd, _("Key slot %d is not used.\n"), keyslot);
return -EINVAL;
}
if (name) {
ci = crypt_status(NULL, name);
- if (ci == INVALID)
+ if (ci == CRYPT_INVALID)
return -EINVAL;
- else if (ci >= ACTIVE) {
+ else if (ci >= CRYPT_ACTIVE) {
log_err(cd, _("Device %s already exists.\n"), name);
return -EEXIST;
}
if (name) {
ci = crypt_status(NULL, name);
- if (ci == INVALID)
+ if (ci == CRYPT_INVALID)
return -EINVAL;
- else if (ci >= ACTIVE) {
+ else if (ci >= CRYPT_ACTIVE) {
log_err(cd, _("Device %s already exists.\n"), name);
return -EEXIST;
}
if (name) {
ci = crypt_status(NULL, name);
- if (ci == INVALID)
+ if (ci == CRYPT_INVALID)
return -EINVAL;
- else if (ci >= ACTIVE) {
+ else if (ci >= CRYPT_ACTIVE) {
log_err(cd, _("Device %s already exists.\n"), name);
return -EEXIST;
}
return -ENOSYS;
switch (crypt_status(cd, name)) {
- case ACTIVE: r = dm_remove_device(name, 0, 0);
- break;
- case BUSY: log_err(cd, _("Device %s is busy.\n"), name);
- r = -EBUSY;
- break;
- case INACTIVE: log_err(cd, _("Device %s is not active.\n"), name);
- r = -ENODEV;
- break;
- default: log_err(cd, _("Invalid device %s.\n"), name);
- r = -EINVAL;
+ case CRYPT_ACTIVE:
+ r = dm_remove_device(name, 0, 0);
+ break;
+ case CRYPT_BUSY:
+ log_err(cd, _("Device %s is busy.\n"), name);
+ r = -EBUSY;
+ break;
+ case CRYPT_INACTIVE:
+ log_err(cd, _("Device %s is not active.\n"), name);
+ r = -ENODEV;
+ break;
+ default:
+ log_err(cd, _("Invalid device %s.\n"), name);
+ r = -EINVAL;
}
if (!cd)
int r;
if (!cd && dm_init(NULL, 1) < 0)
- return INVALID;
+ return CRYPT_INVALID;
r = dm_status_device(name);
dm_exit();
if (r < 0 && r != -ENODEV)
- return INVALID;
+ return CRYPT_INVALID;
if (r == 0)
- return ACTIVE;
+ return CRYPT_ACTIVE;
if (r > 0)
- return BUSY;
+ return CRYPT_BUSY;
- return INACTIVE;
+ return CRYPT_INACTIVE;
}
static void hexprintICB(struct crypt_device *cd, char *d, int n)
{
if (!isLUKS(cd->type)) {
log_err(cd, _("This operation is supported only for LUKS device.\n"));
- return SLOT_INVALID;
+ return CRYPT_SLOT_INVALID;
}
return LUKS_keyslot_info(&cd->hdr, keyslot);
log_dbg("Trying to open key slot %d [%d].", keyIndex, (int)ki);
- if (ki < SLOT_ACTIVE)
+ if (ki < CRYPT_SLOT_ACTIVE)
return -ENOENT;
// assert((mk->keyLength % TWOFISH_BLOCKSIZE) == 0); FIXME
int i;
if(keyslot >= LUKS_NUMKEYS || keyslot < 0)
- return SLOT_INVALID;
+ return CRYPT_SLOT_INVALID;
if (hdr->keyblock[keyslot].active == LUKS_KEY_DISABLED)
- return SLOT_INACTIVE;
+ return CRYPT_SLOT_INACTIVE;
if (hdr->keyblock[keyslot].active != LUKS_KEY_ENABLED)
- return SLOT_INVALID;
+ return CRYPT_SLOT_INVALID;
for(i = 0; i < LUKS_NUMKEYS; i++)
if(i != keyslot && hdr->keyblock[i].active == LUKS_KEY_ENABLED)
- return SLOT_ACTIVE;
+ return CRYPT_SLOT_ACTIVE;
- return SLOT_ACTIVE_LAST;
+ return CRYPT_SLOT_ACTIVE_LAST;
}
int LUKS_keyslot_find_empty(struct luks_phdr *hdr)
{
crypt_keyslot_info ki = LUKS_keyslot_info(hdr, keyslot);
- if (ki == SLOT_INVALID)
+ if (ki == CRYPT_SLOT_INVALID)
return -EINVAL;
hdr->keyblock[keyslot].active = enable ? LUKS_KEY_ENABLED : LUKS_KEY_DISABLED;
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
// device status check
- EQ_(crypt_status(cd, CDEVICE_1), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
snprintf(path, sizeof(path), "%s/%s", crypt_get_dir(), CDEVICE_1);
fd = open(path, O_RDONLY);
- EQ_(crypt_status(cd, CDEVICE_1), BUSY);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_BUSY);
FAIL_(crypt_deactivate(cd, CDEVICE_1), "Device is busy");
close(fd);
OK_(crypt_deactivate(cd, CDEVICE_1));
- EQ_(crypt_status(cd, CDEVICE_1), INACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
- EQ_(crypt_status(cd, CDEVICE_1), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
// retrieve volume key check
memset(key2, 0, key_size);
OK_(crypt_init(&cd, DEVICE_1));
OK_(crypt_load(cd, CRYPT_LUKS1, NULL));
- EQ_(crypt_status(cd, CDEVICE_1), INACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_INACTIVE);
OK_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0));
FAIL_(crypt_activate_by_passphrase(cd, CDEVICE_1, CRYPT_ANY_SLOT, KEY1, strlen(KEY1), 0), "already open");
- EQ_(crypt_status(cd, CDEVICE_1), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1));
FAIL_(crypt_deactivate(cd, CDEVICE_1), "no such device");
EQ_(0, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key, &key_size, KEY1, strlen(KEY1)));
OK_(crypt_volume_key_verify(cd, key, key_size));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_1, key, key_size, 0));
- EQ_(crypt_status(cd, CDEVICE_1), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_1), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_1));
key[1] = ~key[1];
// even with no keyslots defined it can be activated by volume key
OK_(crypt_volume_key_verify(cd, key, key_size));
OK_(crypt_activate_by_volume_key(cd, CDEVICE_2, key, key_size, 0));
- EQ_(crypt_status(cd, CDEVICE_2), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_2));
// now with keyslot
EQ_(7, crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)));
- EQ_(SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 7));
+ EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 7));
EQ_(7, crypt_activate_by_passphrase(cd, CDEVICE_2, CRYPT_ANY_SLOT, passphrase, strlen(passphrase), 0));
- EQ_(crypt_status(cd, CDEVICE_2), ACTIVE);
+ EQ_(crypt_status(cd, CDEVICE_2), CRYPT_ACTIVE);
OK_(crypt_deactivate(cd, CDEVICE_2));
FAIL_(crypt_keyslot_add_by_volume_key(cd, 7, key, key_size, passphrase, strlen(passphrase)), "slot used");
FAIL_(crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)), "key mismatch");
key[1] = ~key[1];
EQ_(6, crypt_keyslot_add_by_volume_key(cd, 6, key, key_size, passphrase, strlen(passphrase)));
- EQ_(SLOT_ACTIVE, crypt_keyslot_status(cd, 6));
+ EQ_(CRYPT_SLOT_ACTIVE, crypt_keyslot_status(cd, 6));
FAIL_(crypt_keyslot_destroy(cd, 8), "invalid keyslot");
FAIL_(crypt_keyslot_destroy(cd, CRYPT_ANY_SLOT), "invalid keyslot");
FAIL_(crypt_keyslot_destroy(cd, 0), "keyslot not used");
OK_(crypt_keyslot_destroy(cd, 7));
- EQ_(SLOT_INACTIVE, crypt_keyslot_status(cd, 7));
- EQ_(SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 6));
+ EQ_(CRYPT_SLOT_INACTIVE, crypt_keyslot_status(cd, 7));
+ EQ_(CRYPT_SLOT_ACTIVE_LAST, crypt_keyslot_status(cd, 6));
EQ_(6, crypt_volume_key_get(cd, CRYPT_ANY_SLOT, key2, &key_size, passphrase, strlen(passphrase)));
OK_(crypt_volume_key_verify(cd, key2, key_size));