vserver 1.9.5.x5
[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         task->tk_msg.rpc_cred->cr_flags |= RPCAUTH_CRED_UPTODATE;
104         return 0;
105 }
106
107 static u32 *
108 nul_validate(struct rpc_task *task, u32 *p)
109 {
110         rpc_authflavor_t        flavor;
111         u32                     size;
112
113         flavor = ntohl(*p++);
114         if (flavor != RPC_AUTH_NULL) {
115                 printk("RPC: bad verf flavor: %u\n", flavor);
116                 return NULL;
117         }
118
119         size = ntohl(*p++);
120         if (size != 0) {
121                 printk("RPC: bad verf size: %u\n", size);
122                 return NULL;
123         }
124
125         return p;
126 }
127
128 struct rpc_authops      authnull_ops = {
129         .owner          = THIS_MODULE,
130         .au_flavor      = RPC_AUTH_NULL,
131 #ifdef RPC_DEBUG
132         .au_name        = "NULL",
133 #endif
134         .create         = nul_create,
135         .destroy        = nul_destroy,
136         .crcreate       = nul_create_cred,
137 };
138
139 static
140 struct rpc_credops      null_credops = {
141         .crdestroy      = nul_destroy_cred,
142         .crmatch        = nul_match,
143         .crmarshal      = nul_marshal,
144         .crrefresh      = nul_refresh,
145         .crvalidate     = nul_validate,
146 };