Error handling improvement thanks to Erik Edin.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@28 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Clemens Fruhwirth
2008-08-20 10:40:45 +00:00
parent 643aed1891
commit 4884064723
5 changed files with 12 additions and 171 deletions

View File

@@ -1,165 +0,0 @@
/* config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if translation of program messages to the user's native
language is requested. */
#undef ENABLE_NLS
/* Definition for the gettext package name */
#undef GETTEXT_PACKAGE
/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
CoreFoundation framework. */
#undef HAVE_CFLOCALECOPYCURRENT
/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
the CoreFoundation framework. */
#undef HAVE_CFPREFERENCESCOPYAPPVALUE
/* Define to 1 if you have the <ctype.h> header file. */
#undef HAVE_CTYPE_H
/* Define if the GNU dcgettext() function is already present or preinstalled.
*/
#undef HAVE_DCGETTEXT
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
*/
#undef HAVE_DIRENT_H
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef HAVE_DLFCN_H
/* Define to 1 if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if the GNU gettext() function is already present or preinstalled. */
#undef HAVE_GETTEXT
/* Define if you have the iconv() function. */
#undef HAVE_ICONV
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the `devmapper' library (-ldevmapper). */
#undef HAVE_LIBDEVMAPPER
/* Define to 1 if you have the `popt' library (-lpopt). */
#undef HAVE_LIBPOPT
/* Define to 1 if you have the `selinux' library (-lselinux). */
#undef HAVE_LIBSELINUX
/* Define to 1 if you have the `sepol' library (-lsepol). */
#undef HAVE_LIBSEPOL
/* Define to 1 if you have the `uuid' library (-luuid). */
#undef HAVE_LIBUUID
/* Define to 1 if you have the <locale.h> header file. */
#undef HAVE_LOCALE_H
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
/* Define to 1 if you have the `setlocale' function. */
#undef HAVE_SETLOCALE
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if `st_rdev' is member of `struct stat'. */
#undef HAVE_STRUCT_STAT_ST_RDEV
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
#undef HAVE_ST_RDEV
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_DIR_H
/* Define to 1 if you have the <sys/ioctl.h> header file. */
#undef HAVE_SYS_IOCTL_H
/* Define to 1 if you have the <sys/mman.h> header file. */
#undef HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
*/
#undef HAVE_SYS_NDIR_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <uuid/uuid.h> header file. */
#undef HAVE_UUID_UUID_H
/* Name of package */
#undef PACKAGE
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
/* Define if you wish to use the plugin loader */
#undef USE_PLUGINS
/* Version number of package */
#undef VERSION
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
/* Number of bits in a file offset, on hosts where this is settable. */
#undef _FILE_OFFSET_BITS
/* Enable GNU extensions on systems that have them. */
#ifndef _GNU_SOURCE
# undef _GNU_SOURCE
#endif
/* Define for large files, on AIX-style hosts. */
#undef _LARGE_FILES
/* Define to empty if `const' does not conform to ANSI C. */
#undef const
/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t

View File

@@ -418,7 +418,7 @@ static int __crypt_luks_format(int arg, struct setup_backend *backend, struct cr
} }
mk = LUKS_generate_masterkey(options->key_size); mk = LUKS_generate_masterkey(options->key_size);
if(NULL == mk) return -ENOMEM; if(NULL == mk) return -ENOMEM; // FIXME This may be misleading, since we don't know what went wrong
#ifdef LUKS_DEBUG #ifdef LUKS_DEBUG
#define printoffset(entry) logger(options, CRYPT_LOG_ERROR, ("offset of " #entry " = %d\n", (char *)(&header.entry)-(char *)(&header)) #define printoffset(entry) logger(options, CRYPT_LOG_ERROR, ("offset of " #entry " = %d\n", (char *)(&header.entry)-(char *)(&header))

View File

@@ -243,6 +243,7 @@ ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offse
memcpy(frontPadBuf+frontHang, buf, innerCount); memcpy(frontPadBuf+frontHang, buf, innerCount);
lseek(fd, offset - frontHang, SEEK_SET);
r = write(fd,frontPadBuf,bsize); r = write(fd,frontPadBuf,bsize);
if(r < 0) return -1; if(r < 0) return -1;
@@ -251,7 +252,7 @@ ssize_t write_lseek_blockwise(int fd, const char *buf, size_t count, off_t offse
} }
if(count <= 0) return buf - orig_buf; if(count <= 0) return buf - orig_buf;
return write_blockwise(fd, buf, count); return write_blockwise(fd, buf, count) + innerCount;
} }
/* Password reading helpers */ /* Password reading helpers */

View File

@@ -50,6 +50,7 @@ static inline int round_up_modulo(int x, int m) {
struct luks_masterkey *LUKS_alloc_masterkey(int keylength) struct luks_masterkey *LUKS_alloc_masterkey(int keylength)
{ {
struct luks_masterkey *mk=malloc(sizeof(*mk) + keylength); struct luks_masterkey *mk=malloc(sizeof(*mk) + keylength);
if(NULL == mk) return NULL;
mk->keyLength=keylength; mk->keyLength=keylength;
return mk; return mk;
} }
@@ -66,7 +67,13 @@ void LUKS_dealloc_masterkey(struct luks_masterkey *mk)
struct luks_masterkey *LUKS_generate_masterkey(int keylength) struct luks_masterkey *LUKS_generate_masterkey(int keylength)
{ {
struct luks_masterkey *mk=LUKS_alloc_masterkey(keylength); struct luks_masterkey *mk=LUKS_alloc_masterkey(keylength);
getRandom(mk->key,keylength); if(NULL == mk) return NULL;
int r = getRandom(mk->key,keylength);
if(r < 0) {
LUKS_dealloc_masterkey(mk);
return NULL;
}
return mk; return mk;
} }

View File

@@ -23,8 +23,6 @@ int openRandom() {
closeRandom */ closeRandom */
int getRandom(char *buf, size_t len) int getRandom(char *buf, size_t len)
{ {
int r = 0;
if(openRandom() == -1) { if(openRandom() == -1) {
perror("getRandom:"); perror("getRandom:");
return -EINVAL; return -EINVAL;
@@ -37,7 +35,7 @@ int getRandom(char *buf, size_t len)
} }
len-= r; buf += r; len-= r; buf += r;
} }
return r; return 0;
} }
void closeRandom() { void closeRandom() {