Import 2.3.13
[davej-history.git] / net / sunrpc / auth_null.c
blobbe6d196376a23850735dc7ec7a911841d0e7aba1
1 /*
2 * linux/net/sunrpc/rpcauth_null.c
4 * AUTH_NULL authentication. Really :-)
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
9 #include <linux/types.h>
10 #include <linux/malloc.h>
11 #include <linux/socket.h>
12 #include <linux/in.h>
13 #include <linux/utsname.h>
14 #include <linux/sunrpc/clnt.h>
16 #ifdef RPC_DEBUG
17 # define RPCDBG_FACILITY RPCDBG_AUTH
18 #endif
20 static struct rpc_auth *
21 nul_create(struct rpc_clnt *clnt)
23 struct rpc_auth *auth;
25 dprintk("RPC: creating NULL authenticator for client %p\n", clnt);
26 if (!(auth = (struct rpc_auth *) rpc_allocate(0, sizeof(*auth))))
27 return NULL;
28 auth->au_cslack = 4;
29 auth->au_rslack = 2;
30 auth->au_ops = &authnull_ops;
31 auth->au_expire = 1800 * HZ;
32 rpcauth_init_credcache(auth);
34 return (struct rpc_auth *) auth;
37 static void
38 nul_destroy(struct rpc_auth *auth)
40 dprintk("RPC: destroying NULL authenticator %p\n", auth);
41 rpc_free(auth);
45 * Create NULL creds for current process
47 static struct rpc_cred *
48 nul_create_cred(struct rpc_task *task)
50 struct rpc_cred *cred;
52 if (!(cred = (struct rpc_cred *) rpc_malloc(task, sizeof(*cred)))) {
53 task->tk_status = -ENOMEM;
54 return NULL;
57 cred->cr_count = 0;
58 cred->cr_flags = RPCAUTH_CRED_UPTODATE;
60 return cred;
64 * Destroy cred handle.
66 static void
67 nul_destroy_cred(struct rpc_cred *cred)
69 rpc_free(cred);
73 * Match cred handle against current process
75 static int
76 nul_match(struct rpc_task *task, struct rpc_cred *cred)
78 return 1;
82 * Marshal credential.
84 static u32 *
85 nul_marshal(struct rpc_task *task, u32 *p, int ruid)
87 *p++ = htonl(RPC_AUTH_NULL);
88 *p++ = 0;
89 *p++ = htonl(RPC_AUTH_NULL);
90 *p++ = 0;
92 return p;
96 * Refresh credential. This is a no-op for AUTH_NULL
98 static int
99 nul_refresh(struct rpc_task *task)
101 return task->tk_status = -EACCES;
104 static u32 *
105 nul_validate(struct rpc_task *task, u32 *p)
107 u32 n = ntohl(*p++);
109 if (n != RPC_AUTH_NULL) {
110 printk("RPC: bad verf flavor: %ld\n", (unsigned long) n);
111 return NULL;
113 if ((n = ntohl(*p++)) != 0) {
114 printk("RPC: bad verf size: %ld\n", (unsigned long) n);
115 return NULL;
118 return p;
121 struct rpc_authops authnull_ops = {
122 RPC_AUTH_NULL,
123 #ifdef RPC_DEBUG
124 "NULL",
125 #endif
126 nul_create,
127 nul_destroy,
128 nul_create_cred,
129 nul_destroy_cred,
130 nul_match,
131 nul_marshal,
132 nul_refresh,
133 nul_validate