From: Milan Broz Date: Sat, 14 Nov 2009 21:33:16 +0000 (+0000) Subject: Add CRYPT_ prefix to enum defined in libcryptsetup.h. X-Git-Tag: upstream/1.6~694 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e698843420ea7d42045bc2aed2d1518a97c930e3;p=platform%2Fupstream%2Fcryptsetup.git Add CRYPT_ prefix to enum defined in libcryptsetup.h. (Avoid collision with other defines.) git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@136 36d66b0a-2a48-0410-832c-cd162a569da5 --- diff --git a/ChangeLog b/ChangeLog index 476485b..d50e5ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-11-14 Milan Broz + * Add CRYPT_ prefix to enum defined in libcryptsetup.h. + 2009-09-30 Milan Broz * Fix exported symbols and versions in libcryptsetup. * Do not use internal lib functions in cryptsetup. diff --git a/lib/libcryptsetup.h b/lib/libcryptsetup.h index 82f885b..f5fa9a8 100644 --- a/lib/libcryptsetup.h +++ b/lib/libcryptsetup.h @@ -407,11 +407,16 @@ int crypt_volume_key_verify(struct crypt_device *cd, * @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); /** @@ -448,7 +453,12 @@ int crypt_get_volume_key_size(struct crypt_device *cd); * @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); /** diff --git a/lib/setup.c b/lib/setup.c index 13db12f..101caba 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -167,11 +167,11 @@ static int keyslot_verify_or_find_empty(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"), @@ -199,14 +199,14 @@ static int verify_other_keyslot(struct crypt_device *cd, 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); @@ -295,19 +295,19 @@ static int luks_remove_helper(struct crypt_device *cd, } 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))) { @@ -349,13 +349,13 @@ static int create_device_helper(struct crypt_device *cd, 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; } @@ -1028,10 +1028,10 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name) 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; } @@ -1251,7 +1251,7 @@ int crypt_suspend(struct crypt_device *cd, 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; } @@ -1597,12 +1597,12 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot) } 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; } @@ -1639,9 +1639,9 @@ int crypt_activate_by_passphrase(struct crypt_device *cd, 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; } @@ -1692,9 +1692,9 @@ int crypt_activate_by_keyfile(struct crypt_device *cd, 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; } @@ -1749,9 +1749,9 @@ int crypt_activate_by_volume_key(struct crypt_device *cd, 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; } @@ -1786,16 +1786,20 @@ int crypt_deactivate(struct crypt_device *cd, const char *name) 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) @@ -1913,7 +1917,7 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *name) int r; if (!cd && dm_init(NULL, 1) < 0) - return INVALID; + return CRYPT_INVALID; r = dm_status_device(name); @@ -1921,15 +1925,15 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *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) @@ -2044,7 +2048,7 @@ crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot) { 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); diff --git a/luks/keymanage.c b/luks/keymanage.c index 6bcfdb3..54d322a 100644 --- a/luks/keymanage.c +++ b/luks/keymanage.c @@ -585,7 +585,7 @@ int LUKS_open_key(const char *device, 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 @@ -755,19 +755,19 @@ crypt_keyslot_info LUKS_keyslot_info(struct luks_phdr *hdr, int keyslot) 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) @@ -799,7 +799,7 @@ int LUKS_keyslot_set(struct luks_phdr *hdr, int keyslot, int enable) { 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; diff --git a/tests/apitest.c b/tests/apitest.c index b4c57d1..f65770f 100644 --- a/tests/apitest.c +++ b/tests/apitest.c @@ -518,17 +518,17 @@ static void AddDevicePlain(void) 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); @@ -556,10 +556,10 @@ static void UseLuksDevice(void) 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"); @@ -573,7 +573,7 @@ static void UseLuksDevice(void) 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]; @@ -635,14 +635,14 @@ static void AddDeviceLuks(void) // 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"); @@ -650,14 +650,14 @@ static void AddDeviceLuks(void) 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));