[PATCH] cryptsetup-luks: use set_error instead of printf in library to report errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

use set_error instead of printf in library to report errors.

Signed-off-by: Ludwig Nussel <ludwig.nussel@xxxxxxx>

Index: cryptsetup-luks-1.0.4_SVN29/lib/setup.c
===================================================================
--- cryptsetup-luks-1.0.4_SVN29.orig/lib/setup.c
+++ cryptsetup-luks-1.0.4_SVN29/lib/setup.c
@@ -98,7 +98,7 @@ static int timed_read(int fd, char *pass
 	if (select(fd+1, &fds, NULL, NULL, &t) > 0)
 		failed = untimed_read(fd, pass, maxlen);
 	else
-		fprintf(stderr, "Operation timed out.\n");
+		set_error("Operation timed out");
 	return failed;
 }
 
@@ -197,14 +197,16 @@ static int get_key(struct crypt_options 
 
 		pass = safe_alloc(512);
 		if (!pass || (i = interactive_pass(prompt, pass, 512, options->timeout))) {
-			set_error("Error reading passphrase");
+			if(!get_error())
+				set_error("Error reading passphrase");
 			goto out_err;
 		}
 		if (verify || verify_if_possible) {
 			char pass_verify[512];
 			i = interactive_pass("Verify passphrase: ", pass_verify, sizeof(pass_verify), options->timeout);
 			if (i || strcmp(pass, pass_verify) != 0) {
-				set_error("Passphrases do not match");
+				if(!get_error())
+					set_error("Passphrases do not match");
 				goto out_err;
 			}
 			memset(pass_verify, 0, sizeof(pass_verify));
@@ -385,7 +387,7 @@ static int parse_into_name_and_mode(cons
 			strncpy(mode,"cbc-plain",10);
 		} 
 		else {
-			fprintf(stderr, "no known cipher-spec pattern detected\n");
+			set_error("no known cipher-spec pattern detected");
 			return -EINVAL;
 		}
 	}
@@ -643,7 +645,6 @@ start:
 		r = -EINVAL; goto out;
 	}
 	if((r = LUKS_open_any_key(options->device, password, passwordLen, &hdr, &mk, backend)) < 0) {
-		set_error("No key available with this passphrase.\n");
 		goto out1;
 	}
 	
Index: cryptsetup-luks-1.0.4_SVN29/luks/keymanage.c
===================================================================
--- cryptsetup-luks-1.0.4_SVN29.orig/luks/keymanage.c
+++ cryptsetup-luks-1.0.4_SVN29/luks/keymanage.c
@@ -76,20 +76,20 @@ int LUKS_read_phdr(const char *device, s
 	
 	devfd = open(device,O_RDONLY | O_DIRECT | O_SYNC);
 	if(-1 == devfd) {
-		fprintf(stderr, _("Can't open device: %s\n"), device);
+		set_error(_("Can't open device %s"), device);
 		return -EINVAL; 
 	}
 
 	if(read_blockwise(devfd, hdr, sizeof(struct luks_phdr)) < sizeof(struct luks_phdr)) {
 		r = -EIO;
 	} else if(memcmp(hdr->magic, luksMagic, LUKS_MAGIC_L)) { /* Check magic */
-		fprintf(stderr, _("%s is not a LUKS partition\n"), device);
+		set_error(_("%s is not a LUKS partition\n"), device);
 		r = -EINVAL;
 	} else if(memcmp(hdr->hashSpec, "sha1", 4)) { /* Check for SHA1 - other hashspecs are not implemented ATM */
-		fputs(_("unknown hash spec in phdr"), stderr);
+		set_error(_("unknown hash spec in phdr"));
 		r = -EINVAL;
 	} else if((hdr->version = ntohs(hdr->version)) != 1) {	/* Convert every uint16/32_t item from network byte order */
-		fprintf(stderr, _("unknown version %d\n"), hdr->version);
+		set_error( _("unknown LUKS version %d\n"), hdr->version);
 		r = -EINVAL;
 	} else {
 		hdr->payloadOffset      = ntohl(hdr->payloadOffset);
@@ -117,7 +117,7 @@ int LUKS_write_phdr(const char *device, 
 	
 	devfd = open(device,O_RDWR | O_DIRECT | O_SYNC);
 	if(-1 == devfd) { 
-		fprintf(stderr, _("Can't open device: %s\n"), device);
+		set_error(_("Can't open device %s"), device);
 		return -EINVAL;
 	}
 
@@ -210,12 +210,12 @@ int LUKS_set_key(const char *device, uns
 	int r;
 	
 	if(hdr->keyblock[keyIndex].active != LUKS_KEY_DISABLED) {
-		fprintf(stderr, _("key %d active, purge first.\n"), keyIndex);
+		set_error( _("key %d active, purge first"), keyIndex);
 		return -EINVAL;
 	}
 		
 	if(hdr->keyblock[keyIndex].stripes < LUKS_STRIPES) {
-	        fprintf(stderr,_("key material section %d includes too few stripes. Header manipulation?\n"),keyIndex);
+	        set_error(_("key material section %d includes too few stripes. Header manipulation?"),keyIndex);
 	         return -EINVAL;
 	}
 	r = getRandom(hdr->keyblock[keyIndex].passwordSalt, LUKS_SALTSIZE);
@@ -247,7 +247,8 @@ int LUKS_set_key(const char *device, uns
 				    hdr->keyblock[keyIndex].keyMaterialOffset,
 				    backend);
 	if(r < 0) {
-		fprintf(stderr,"Failed to write to key storage.\n");
+		if(!get_error())
+			set_error("Failed to write to key storage");
 		goto out;
 	}
 
@@ -303,7 +304,8 @@ int LUKS_open_key(const char *device, 
 				      hdr->keyblock[keyIndex].keyMaterialOffset,
 				      backend);
 	if(r < 0) {
-		fprintf(stderr,"Failed to read from key storage\n");
+		if(!get_error())
+			set_error("Failed to read from key storage");
 		goto out;
 	}
 
@@ -387,7 +389,7 @@ static int wipe(const char *device, unsi
 	
 	devfd = open(device, O_RDWR | O_DIRECT);
 	if(devfd == -1) {
-		fprintf(stderr, _("Can't open device: %s\n"), device);
+		set_error(_("Can't open device %s"), device);
 		return -EINVAL;
 	}
 
Index: cryptsetup-luks-1.0.4_SVN29/lib/utils.c
===================================================================
--- cryptsetup-luks-1.0.4_SVN29.orig/lib/utils.c
+++ cryptsetup-luks-1.0.4_SVN29/lib/utils.c
@@ -225,7 +225,7 @@ ssize_t read_blockwise(int fd, void *ori
 	while(count) {
 		r = read(fd,padbuf,bsize);
 		if(r < 0 || r != bsize) {
-			fprintf(stderr, "read failed in read_blockwise.\n");
+			set_error("read failed in read_blockwise()");
 			goto out;
 		}
 		step = count<bsize?count:bsize;
Index: cryptsetup-luks-1.0.4_SVN29/luks/keyencryption.c
===================================================================
--- cryptsetup-luks-1.0.4_SVN29.orig/luks/keyencryption.c
+++ cryptsetup-luks-1.0.4_SVN29/luks/keyencryption.c
@@ -58,7 +58,7 @@ static int setup_mapping(const char *cip
 	 * device's sector size, otherwise the mapping will be refused.
 	 */
 	if(device_sector_size < 0) {
-		fprintf(stderr,_("Unable to obtain sector size for %s"),device);
+		set_error(_("Unable to obtain sector size for %s"),device);
 		return -EINVAL;
 	}
 	options->size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
@@ -118,7 +118,8 @@ static int LUKS_endec_template(char *src
 
 	r = setup_mapping(dmCipherSpec,name,device,hdr->payloadOffset,key,keyLength,sector,srcLength,backend,mode);
 	if(r < 0) {
-		fprintf(stderr,"Failed to setup dm-crypt key mapping.\nCheck kernel for support for the %s cipher spec and verify that %s contains at least %d sectors.\n",
+		if(!get_error())
+			set_error("Failed to setup dm-crypt key mapping.\nCheck kernel for support for the %s cipher spec and verify that %s contains at least %d sectors",
 			dmCipherSpec, 
 			device, 
 			sector + div_round_up(srcLength,SECTOR_SIZE));
-- 
 (o_   Ludwig Nussel
 //\   SUSE Labs
 V_/_  http://www.suse.de/
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)


---------------------------------------------------------------------
dm-crypt mailing list - http://www.saout.de/misc/dm-crypt/
To unsubscribe, e-mail: dm-crypt-unsubscribe@xxxxxxxx
For additional commands, e-mail: dm-crypt-help@xxxxxxxx


[Index of Archives]     [Device Mapper Devel]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux