diff --git a/lib/libcryptsetup.h b/lib/libcryptsetup.h index 3f6e3cbe..15138d6c 100644 --- a/lib/libcryptsetup.h +++ b/lib/libcryptsetup.h @@ -1084,28 +1084,6 @@ int crypt_header_restore(struct crypt_device *cd, const char *requested_type, const char *backup_file); -/** - * Receive last reported error, DEPRECATED. - * - * @param cd crypt device handle - * @param buf buffef for message - * @param size size of buffer - * - * @note This function is DEPRECATED and will be removed in future versions. - * @note All error messages are reported also through log callback. - */ -void crypt_last_error(struct crypt_device *cd, char *buf, size_t size); - -/** - * Receives last reported error, DEPRECATED - * - * @param buf buffef for message - * @param size size of buffer - * - * @note This function is DEPRECATED and will be removed in future versions. - */ -void crypt_get_error(char *buf, size_t size); - /** * Get directory where mapped crypt devices are created * diff --git a/lib/libcryptsetup.sym b/lib/libcryptsetup.sym index ca9a5017..3d0f78e8 100644 --- a/lib/libcryptsetup.sym +++ b/lib/libcryptsetup.sym @@ -55,8 +55,6 @@ CRYPTSETUP_1.0 { crypt_keyslot_max; crypt_keyslot_area; crypt_keyslot_status; - crypt_last_error; - crypt_get_error; crypt_get_dir; crypt_set_debug_level; crypt_log; diff --git a/lib/setup.c b/lib/setup.c index bf24f50c..5617879b 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -90,18 +90,11 @@ struct crypt_device { void *log_usrptr; int (*confirm)(const char *msg, void *usrptr); void *confirm_usrptr; - - /* last error message */ - char error[MAX_ERROR_LENGTH]; }; /* Just to suppress redundant messages about crypto backend */ static int _crypto_logged = 0; -/* Global error */ -/* FIXME: not thread safe, remove this later */ -static char global_error[MAX_ERROR_LENGTH] = {0}; - /* Log helper */ static void (*_default_log)(int level, const char *msg, void *usrptr) = NULL; static int _debug_level = 0; @@ -116,32 +109,12 @@ int crypt_get_debug_level(void) return _debug_level; } -static void crypt_set_error(struct crypt_device *cd, const char *error) -{ - size_t size = strlen(error); - - /* Set global error, ugly hack... */ - strncpy(global_error, error, MAX_ERROR_LENGTH - 2); - if (size < MAX_ERROR_LENGTH && global_error[size - 1] == '\n') - global_error[size - 1] = '\0'; - - /* Set error string per context */ - if (cd) { - strncpy(cd->error, error, MAX_ERROR_LENGTH - 2); - if (size < MAX_ERROR_LENGTH && cd->error[size - 1] == '\n') - cd->error[size - 1] = '\0'; - } -} - void crypt_log(struct crypt_device *cd, int level, const char *msg) { if (cd && cd->log) cd->log(level, msg, cd->log_usrptr); else if (_default_log) _default_log(level, msg, NULL); - - if (level == CRYPT_LOG_ERROR) - crypt_set_error(cd, msg); } __attribute__((format(printf, 5, 6))) @@ -471,30 +444,6 @@ void crypt_set_confirm_callback(struct crypt_device *cd, cd->confirm_usrptr = usrptr; } -static void _get_error(char *error, char *buf, size_t size) -{ - if (!buf || size < 1) - error[0] = '\0'; - else if (*error) { - strncpy(buf, error, size - 1); - buf[size - 1] = '\0'; - error[0] = '\0'; - } else - buf[0] = '\0'; -} - -void crypt_last_error(struct crypt_device *cd, char *buf, size_t size) -{ - if (cd) - return _get_error(cd->error, buf, size); -} - -/* Deprecated global error interface */ -void crypt_get_error(char *buf, size_t size) -{ - return _get_error(global_error, buf, size); -} - const char *crypt_get_dir(void) { return dm_get_dir(); diff --git a/src/utils_tools.c b/src/utils_tools.c index 97c879e4..1bb92462 100644 --- a/src/utils_tools.c +++ b/src/utils_tools.c @@ -164,7 +164,7 @@ int yesDialog(const char *msg, void *usrptr __attribute__((unused))) void show_status(int errcode) { - char error[256]; + char *crypt_error; if(!opt_verbose) return; @@ -174,25 +174,23 @@ void show_status(int errcode) return; } - crypt_get_error(error, sizeof(error)); + if (errcode < 0) + errcode = translate_errno(errcode); - if (*error) { -#ifdef STRERROR_R_CHAR_P /* GNU-specific strerror_r */ - char *error_ = strerror_r(-errcode, error, sizeof(error)); - if (error_ != error) - strncpy(error, error_, sizeof(error)); -#else /* POSIX strerror_r variant */ - if (strerror_r(-errcode, error, sizeof(error))) - *error = '\0'; -#endif - error[sizeof(error) - 1] = '\0'; - } - - log_err(_("Command failed with code %i"), -errcode); - if (*error) - log_err(": %s\n", error); + if (errcode == 1) + crypt_error = _("wrong or missing parameters"); + else if (errcode == 2) + crypt_error = _("no permission or bad passphrase"); + else if (errcode == 3) + crypt_error = _("out of memory"); + else if (errcode == 4) + crypt_error = _("wrong device or file specified"); + else if (errcode == 5) + crypt_error = _("device already exists or device is busy"); else - log_err(".\n"); + crypt_error = _("unknown error"); + + log_std(_("Command failed with code %i (%s).\n"), -errcode, crypt_error); } const char *uuid_or_device(const char *spec)