crypto.c (3fd945a79e147ee10f84213976889b29049c3519) | crypto.c (457117f077c6749d1e28469eae91fb69c9806768) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * The base64 encode/decode code was copied from fscrypt: 4 * Copyright (C) 2015, Google, Inc. 5 * Copyright (C) 2015, Motorola Mobility 6 * Written by Uday Savagaonkar, 2014. 7 * Modified by Jaegeuk Kim, 2015. 8 */ --- 230 unchanged lines hidden (view full) --- 239 } 240 241 /* base64 encode the encrypted name */ 242 elen = ceph_base64_encode(cryptbuf, len, buf); 243 kfree(cryptbuf); 244 dout("base64-encoded ciphertext name = %.*s\n", elen, buf); 245 return elen; 246} | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * The base64 encode/decode code was copied from fscrypt: 4 * Copyright (C) 2015, Google, Inc. 5 * Copyright (C) 2015, Motorola Mobility 6 * Written by Uday Savagaonkar, 2014. 7 * Modified by Jaegeuk Kim, 2015. 8 */ --- 230 unchanged lines hidden (view full) --- 239 } 240 241 /* base64 encode the encrypted name */ 242 elen = ceph_base64_encode(cryptbuf, len, buf); 243 kfree(cryptbuf); 244 dout("base64-encoded ciphertext name = %.*s\n", elen, buf); 245 return elen; 246} |
247 248/** 249 * ceph_fname_to_usr - convert a filename for userland presentation 250 * @fname: ceph_fname to be converted 251 * @tname: temporary name buffer to use for conversion (may be NULL) 252 * @oname: where converted name should be placed 253 * @is_nokey: set to true if key wasn't available during conversion (may be NULL) 254 * 255 * Given a filename (usually from the MDS), format it for presentation to 256 * userland. If @parent is not encrypted, just pass it back as-is. 257 * 258 * Otherwise, base64 decode the string, and then ask fscrypt to format it 259 * for userland presentation. 260 * 261 * Returns 0 on success or negative error code on error. 262 */ 263int ceph_fname_to_usr(const struct ceph_fname *fname, struct fscrypt_str *tname, 264 struct fscrypt_str *oname, bool *is_nokey) 265{ 266 int ret; 267 struct fscrypt_str _tname = FSTR_INIT(NULL, 0); 268 struct fscrypt_str iname; 269 270 if (!IS_ENCRYPTED(fname->dir)) { 271 oname->name = fname->name; 272 oname->len = fname->name_len; 273 return 0; 274 } 275 276 /* Sanity check that the resulting name will fit in the buffer */ 277 if (fname->name_len > NAME_MAX || fname->ctext_len > NAME_MAX) 278 return -EIO; 279 280 ret = __fscrypt_prepare_readdir(fname->dir); 281 if (ret) 282 return ret; 283 284 /* 285 * Use the raw dentry name as sent by the MDS instead of 286 * generating a nokey name via fscrypt. 287 */ 288 if (!fscrypt_has_encryption_key(fname->dir)) { 289 memcpy(oname->name, fname->name, fname->name_len); 290 oname->len = fname->name_len; 291 if (is_nokey) 292 *is_nokey = true; 293 return 0; 294 } 295 296 if (fname->ctext_len == 0) { 297 int declen; 298 299 if (!tname) { 300 ret = fscrypt_fname_alloc_buffer(NAME_MAX, &_tname); 301 if (ret) 302 return ret; 303 tname = &_tname; 304 } 305 306 declen = ceph_base64_decode(fname->name, fname->name_len, 307 tname->name); 308 if (declen <= 0) { 309 ret = -EIO; 310 goto out; 311 } 312 iname.name = tname->name; 313 iname.len = declen; 314 } else { 315 iname.name = fname->ctext; 316 iname.len = fname->ctext_len; 317 } 318 319 ret = fscrypt_fname_disk_to_usr(fname->dir, 0, 0, &iname, oname); 320out: 321 fscrypt_fname_free_buffer(&_tname); 322 return ret; 323} |
|