ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / net / sunrpc / auth_null.c
1 /*
2  * linux/net/sunrpc/auth_null.c
3  *
4  * AUTH_NULL authentication. Really :-)
5  *
6  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #include <linux/types.h>
10 #include <linux/socket.h>
11 #include <linux/module.h>
12 #include <linux/in.h>
13 #include <linux/utsname.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sched.h>
16
17 #ifdef RPC_DEBUG
18 # define RPCDBG_FACILITY        RPCDBG_AUTH
19 #endif
20
21 static struct rpc_credops       null_credops;
22
23 static struct rpc_auth *
24 nul_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
25 {
26         struct rpc_auth *auth;
27
28         dprintk("RPC: creating NULL authenticator for client %p\n", clnt);
29         if (!(auth = (struct rpc_auth *) kmalloc(sizeof(*auth),GFP_KERNEL)))
30                 return NULL;
31         auth->au_cslack = 4;
32         auth->au_rslack = 2;
33         auth->au_ops = &authnull_ops;
34         auth->au_expire = 1800 * HZ;
35         rpcauth_init_credcache(auth);
36
37         return (struct rpc_auth *) auth;
38 }
39
40 static void
41 nul_destroy(struct rpc_auth *auth)
42 {
43         dprintk("RPC: destroying NULL authenticator %p\n", auth);
44         rpcauth_free_credcache(auth);
45 }
46
47 /*
48  * Create NULL creds for current process
49  */
50 static struct rpc_cred *
51 nul_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
52 {
53         struct rpc_cred *cred;
54
55         if (!(cred = (struct rpc_cred *) kmalloc(sizeof(*cred),GFP_KERNEL)))
56                 return NULL;
57         atomic_set(&cred->cr_count, 0);
58         cred->cr_flags = RPCAUTH_CRED_UPTODATE;
59         cred->cr_uid = acred->uid;
60         cred->cr_ops = &null_credops;
61
62         return cred;
63 }
64
65 /*
66  * Destroy cred handle.
67  */
68 static void
69 nul_destroy_cred(struct rpc_cred *cred)
70 {
71         kfree(cred);
72 }
73
74 /*
75  * Match cred handle against current process
76  */
77 static int
78 nul_match(struct auth_cred *acred, struct rpc_cred *cred, int taskflags)
79 {
80         return 1;
81 }
82
83 /*
84  * Marshal credential.
85  */
86 static u32 *
87 nul_marshal(struct rpc_task *task, u32 *p, int ruid)
88 {
89         *p++ = htonl(RPC_AUTH_NULL);
90         *p++ = 0;
91         *p++ = htonl(RPC_AUTH_NULL);
92         *p++ = 0;
93
94         return p;
95 }
96
97 /*
98  * Refresh credential. This is a no-op for AUTH_NULL
99  */
100 static int
101 nul_refresh(struct rpc_task *task)
102 {
103         return task->tk_status = -EACCES;
104 }
105
106 static u32 *
107 nul_validate(struct rpc_task *task, u32 *p)
108 {
109         rpc_authflavor_t        flavor;
110         u32                     size;
111
112         flavor = ntohl(*p++);
113         if (flavor != RPC_AUTH_NULL) {
114                 printk("RPC: bad verf flavor: %u\n", flavor);
115                 return NULL;
116         }
117
118         size = ntohl(*p++);
119         if (size != 0) {
120                 printk("RPC: bad verf size: %u\n", size);
121                 return NULL;
122         }
123
124         return p;
125 }
126
127 struct rpc_authops      authnull_ops = {
128         .owner          = THIS_MODULE,
129         .au_flavor      = RPC_AUTH_NULL,
130 #ifdef RPC_DEBUG
131         .au_name        = "NULL",
132 #endif
133         .create         = nul_create,
134         .destroy        = nul_destroy,
135         .crcreate       = nul_create_cred,
136 };
137
138 static
139 struct rpc_credops      null_credops = {
140         .crdestroy      = nul_destroy_cred,
141         .crmatch        = nul_match,
142         .crmarshal      = nul_marshal,
143         .crrefresh      = nul_refresh,
144         .crvalidate     = nul_validate,
145 };