From maxlor@maxlor.mine.nu  Sun Aug  7 23:36:25 2005
Return-Path: <maxlor@maxlor.mine.nu>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9017F16A41F;
	Sun,  7 Aug 2005 23:36:25 +0000 (GMT)
	(envelope-from maxlor@maxlor.mine.nu)
Received: from maxlor.mine.nu (c-213-160-32-54.customer.ggaweb.ch [213.160.32.54])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2827D43EBD;
	Sun,  7 Aug 2005 23:36:25 +0000 (GMT)
	(envelope-from maxlor@maxlor.mine.nu)
Received: from localhost (localhost [127.0.0.1])
	by maxlor.mine.nu (Postfix) with ESMTP id 1CFFF3C0;
	Mon,  8 Aug 2005 01:36:22 +0200 (CEST)
Received: from maxlor.mine.nu ([127.0.0.1])
 by localhost (midgard [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 28348-09; Mon,  8 Aug 2005 01:36:21 +0200 (CEST)
Received: by maxlor.mine.nu (Postfix, from userid 1000)
	id 09C53347; Mon,  8 Aug 2005 01:36:21 +0200 (CEST)
Message-Id: <20050807233621.09C53347@maxlor.mine.nu>
Date: Mon,  8 Aug 2005 01:36:21 +0200 (CEST)
From: Benjamin Lutz <benlutz@datacomm.ch>
Reply-To: Benjamin Lutz <benlutz@datacomm.ch>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Pawel Jakub Dawidek <pjd@freebsd.org>
Subject: geli accepts only lower case algorithm names
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         84659
>Category:       kern
>Synopsis:       geli accepts only lower case algorithm names
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Aug 07 23:40:15 GMT 2005
>Closed-Date:    Mon Aug 08 19:51:00 GMT 2005
>Last-Modified:  Mon Aug 08 19:51:00 GMT 2005
>Originator:     Benjamin Lutz
>Release:        FreeBSD 6.0-BETA2 amd64
>Organization:
>Environment:
System: FreeBSD merlin 6.0-BETA2 FreeBSD 6.0-BETA2 #4: Mon Aug 8 01:09:06 CEST 2005 root@merlin:/usr/obj/usr/src/sys/MERLIN64 amd64

>Description:
In the geli(8) manpage, it says that either AES, Blowfish or 3DES should
used as algorithm. In practice, however, geli accepts only "aes",
"blowfish" and "3des", ie lower case versions. I think this is a bug,
and either the manpage should be synced with the code, or, better, the
code should allow both upper and lower case names, or only upper case
names.

I have played around with the code a bit, see the diff below.
>How-To-Repeat:
$ geli init -a Blowfish /dev/md0
Invalid encryption algorithm.
$ geli init -a AES /dev/md0
Invalid encryption algorithm.
$
>Fix:

--- g_eli.h.diff begins here ---
--- g_eli.h.orig	Fri Aug  5 21:58:14 2005
+++ g_eli.h	Mon Aug  8 01:27:48 2005
@@ -36,9 +36,11 @@
 #include <opencrypto/cryptodev.h>
 #ifdef _KERNEL
 #include <sys/bio.h>
+#include <sys/ctype.h>
 #include <sys/libkern.h>
 #include <geom/geom.h>
 #else
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 #endif
@@ -222,14 +224,22 @@
 static __inline u_int
 g_eli_str2algo(const char *name)
 {
+	char lc_name[9];
+	unsigned int i;
 
-	if (strcmp("null", name) == 0)
+	strlcpy(lc_name, name, sizeof(lc_name));
+	for(i = 0; lc_name[i] != '\0'; i++)
+	{
+		lc_name[i] = tolower(lc_name[i]);
+	}
+
+	if (strcmp("null", lc_name) == 0)
 		return (CRYPTO_NULL_CBC);
-	if (strcmp("aes", name) == 0)
+	if (strcmp("aes", lc_name) == 0)
 		return (CRYPTO_AES_CBC);
-	else if (strcmp("blowfish", name) == 0)
+	else if (strcmp("blowfish", lc_name) == 0)
 		return (CRYPTO_BLF_CBC);
-	else if (strcmp("3des", name) == 0)
+	else if (strcmp("3des", lc_name) == 0)
 		return (CRYPTO_3DES_CBC);
 	return (CRYPTO_ALGORITHM_MIN - 1);
 }
--- g_eli.h.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pjd 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Aug 7 23:55:06 GMT 2005 
Responsible-Changed-Why:  
Over to author. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84659 
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: Mon Aug 8 19:41:30 GMT 2005 
State-Changed-Why:  
I just added (to libkern) and used strcasecmp(). Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=84659 
>Unformatted:
