aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorMichael Halcrow <mhalcrow@us.ibm.com>2009-01-06 17:42:05 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 18:59:22 -0500
commit71c11c378f46e42ca67c1e227646ce23bf43a8c6 (patch)
tree5762c267801a47bc5efd54242661820472827960 /fs
parent7d8bc2be51706152828164b305e969b4a8471041 (diff)
eCryptfs: Clean up ecryptfs_decode_from_filename()
Flesh out the comments for ecryptfs_decode_from_filename(). Remove the return condition, since it is always 0. Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com> Cc: Dustin Kirkland <dustin.kirkland@gmail.com> Cc: Eric Sandeen <sandeen@redhat.com> Cc: Tyler Hicks <tchicks@us.ibm.com> Cc: David Kleikamp <shaggy@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/ecryptfs/crypto.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index e935a2224982..c01e043670e2 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -1931,7 +1931,7 @@ static unsigned char *portable_filename_chars = ("-.0123456789ABCD"
1931 1931
1932/* We could either offset on every reverse map or just pad some 0x00's 1932/* We could either offset on every reverse map or just pad some 0x00's
1933 * at the front here */ 1933 * at the front here */
1934static unsigned char filename_rev_map[] = { 1934static const unsigned char filename_rev_map[] = {
1935 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */ 1935 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 7 */
1936 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 15 */ 1936 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 15 */
1937 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 23 */ 1937 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 23 */
@@ -2012,16 +2012,30 @@ out:
2012 return; 2012 return;
2013} 2013}
2014 2014
2015int ecryptfs_decode_from_filename(unsigned char *dst, size_t *dst_size, 2015/**
2016 const unsigned char *src, size_t src_size) 2016 * ecryptfs_decode_from_filename
2017 * @dst: If NULL, this function only sets @dst_size and returns. If
2018 * non-NULL, this function decodes the encoded octets in @src
2019 * into the memory that @dst points to.
2020 * @dst_size: Set to the size of the decoded string.
2021 * @src: The encoded set of octets to decode.
2022 * @src_size: The size of the encoded set of octets to decode.
2023 */
2024static void
2025ecryptfs_decode_from_filename(unsigned char *dst, size_t *dst_size,
2026 const unsigned char *src, size_t src_size)
2017{ 2027{
2018 u8 current_bit_offset = 0; 2028 u8 current_bit_offset = 0;
2019 size_t src_byte_offset = 0; 2029 size_t src_byte_offset = 0;
2020 size_t dst_byte_offset = 0; 2030 size_t dst_byte_offset = 0;
2021 int rc = 0;
2022 2031
2023 if (dst == NULL) { 2032 if (dst == NULL) {
2024 /* Not exact; conservatively long */ 2033 /* Not exact; conservatively long. Every block of 4
2034 * encoded characters decodes into a block of 3
2035 * decoded characters. This segment of code provides
2036 * the caller with the maximum amount of allocated
2037 * space that @dst will need to point to in a
2038 * subsequent call. */
2025 (*dst_size) = (((src_size + 1) * 3) / 4); 2039 (*dst_size) = (((src_size + 1) * 3) / 4);
2026 goto out; 2040 goto out;
2027 } 2041 }
@@ -2055,7 +2069,7 @@ int ecryptfs_decode_from_filename(unsigned char *dst, size_t *dst_size,
2055 } 2069 }
2056 (*dst_size) = dst_byte_offset; 2070 (*dst_size) = dst_byte_offset;
2057out: 2071out:
2058 return rc; 2072 return;
2059} 2073}
2060 2074
2061/** 2075/**
@@ -2208,16 +2222,8 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
2208 2222
2209 name += ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE; 2223 name += ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE;
2210 name_size -= ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE; 2224 name_size -= ECRYPTFS_FNEK_ENCRYPTED_FILENAME_PREFIX_SIZE;
2211 rc = ecryptfs_decode_from_filename(NULL, &decoded_name_size, 2225 ecryptfs_decode_from_filename(NULL, &decoded_name_size,
2212 name, name_size); 2226 name, name_size);
2213 if (rc) {
2214 printk(KERN_ERR "%s: Error attempting to decode "
2215 "filename; rc = [%d]\n", __func__, rc);
2216 rc = ecryptfs_copy_filename(plaintext_name,
2217 plaintext_name_size,
2218 orig_name, orig_name_size);
2219 goto out;
2220 }
2221 decoded_name = kmalloc(decoded_name_size, GFP_KERNEL); 2227 decoded_name = kmalloc(decoded_name_size, GFP_KERNEL);
2222 if (!decoded_name) { 2228 if (!decoded_name) {
2223 printk(KERN_ERR "%s: Out of memory whilst attempting " 2229 printk(KERN_ERR "%s: Out of memory whilst attempting "
@@ -2226,17 +2232,8 @@ int ecryptfs_decode_and_decrypt_filename(char **plaintext_name,
2226 rc = -ENOMEM; 2232 rc = -ENOMEM;
2227 goto out; 2233 goto out;
2228 } 2234 }
2229 rc = ecryptfs_decode_from_filename(decoded_name, 2235 ecryptfs_decode_from_filename(decoded_name, &decoded_name_size,
2230 &decoded_name_size, 2236 name, name_size);
2231 name, name_size);
2232 if (rc) {
2233 printk(KERN_ERR "%s: Error attempting to decode "
2234 "filename; rc = [%d]\n", __func__, rc);
2235 rc = ecryptfs_copy_filename(plaintext_name,
2236 plaintext_name_size,
2237 orig_name, orig_name_size);
2238 goto out_free;
2239 }
2240 rc = ecryptfs_parse_tag_70_packet(plaintext_name, 2237 rc = ecryptfs_parse_tag_70_packet(plaintext_name,
2241 plaintext_name_size, 2238 plaintext_name_size,
2242 &packet_size, 2239 &packet_size,