2 * linux/fs/nfsd/nfs4recover.c
4 * Copyright (c) 2004 The Regents of the University of Michigan.
7 * Andy Adamson <andros@citi.umich.edu>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include <linux/sunrpc/svc.h>
38 #include <linux/nfsd/nfsd.h>
39 #include <linux/nfs4.h>
40 #include <linux/nfsd/state.h>
41 #include <linux/nfsd/xdr4.h>
42 #include <asm/uaccess.h>
43 #include <asm/scatterlist.h>
44 #include <linux/crypto.h>
47 #define NFSDDBG_FACILITY NFSDDBG_PROC
50 md5_to_hex(char *out, char *md5)
54 for (i=0; i<16; i++) {
55 unsigned char c = md5[i];
57 *out++ = '0' + ((c&0xf0)>>4) + (c>=0xa0)*('a'-'9'-1);
58 *out++ = '0' + (c&0x0f) + ((c&0x0f)>=0x0a)*('a'-'9'-1);
64 nfs4_make_rec_clidname(char *dname, struct xdr_netobj *clname)
66 struct xdr_netobj cksum;
67 struct crypto_tfm *tfm;
68 struct scatterlist sg[1];
69 int status = nfserr_resource;
71 dprintk("NFSD: nfs4_make_rec_clidname for %.*s\n",
72 clname->len, clname->data);
73 tfm = crypto_alloc_tfm("md5", 0);
76 cksum.len = crypto_tfm_alg_digestsize(tfm);
77 cksum.data = kmalloc(cksum.len, GFP_KERNEL);
78 if (cksum.data == NULL)
80 crypto_digest_init(tfm);
82 sg[0].page = virt_to_page(clname->data);
83 sg[0].offset = offset_in_page(clname->data);
84 sg[0].length = clname->len;
86 crypto_digest_update(tfm, sg, 1);
87 crypto_digest_final(tfm, cksum.data);
89 md5_to_hex(dname, cksum.data);