1 /*
2 * linux/net/sunrpc/rpcauth_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/slab.h>
11 #include <linux/socket.h>
12 #include <linux/in.h>
13 #include <linux/utsname.h>
14 #include <linux/sunrpc/clnt.h>
15
16 #ifdef RPC_DEBUG
17 # define RPCDBG_FACILITY RPCDBG_AUTH
18 #endif
19
20 static struct rpc_credops null_credops;
21
22 static struct rpc_auth *
nul_create(struct rpc_clnt * clnt)23 nul_create(struct rpc_clnt *clnt)
24 {
25 struct rpc_auth *auth;
26
27 dprintk("RPC: creating NULL authenticator for client %p\n", clnt);
28 if (!(auth = (struct rpc_auth *) rpc_allocate(0, sizeof(*auth))))
29 return NULL;
30 auth->au_cslack = 4;
31 auth->au_rslack = 2;
32 auth->au_ops = &authnull_ops;
33 auth->au_expire = 1800 * HZ;
34 rpcauth_init_credcache(auth);
35
36 return (struct rpc_auth *) auth;
37 }
38
39 static void
nul_destroy(struct rpc_auth * auth)40 nul_destroy(struct rpc_auth *auth)
41 {
42 dprintk("RPC: destroying NULL authenticator %p\n", auth);
43 rpcauth_free_credcache(auth);
44 rpc_free(auth);
45 }
46
47 /*
48 * Create NULL creds for current process
49 */
50 static struct rpc_cred *
nul_create_cred(int flags)51 nul_create_cred(int flags)
52 {
53 struct rpc_cred *cred;
54
55 if (!(cred = (struct rpc_cred *) rpc_allocate(flags, sizeof(*cred))))
56 return NULL;
57 atomic_set(&cred->cr_count, 0);
58 cred->cr_flags = RPCAUTH_CRED_UPTODATE;
59 cred->cr_uid = current->uid;
60 cred->cr_ops = &null_credops;
61
62 return cred;
63 }
64
65 /*
66 * Destroy cred handle.
67 */
68 static void
nul_destroy_cred(struct rpc_cred * cred)69 nul_destroy_cred(struct rpc_cred *cred)
70 {
71 rpc_free(cred);
72 }
73
74 /*
75 * Match cred handle against current process
76 */
77 static int
nul_match(struct rpc_cred * cred,int taskflags)78 nul_match(struct rpc_cred *cred, int taskflags)
79 {
80 return 1;
81 }
82
83 /*
84 * Marshal credential.
85 */
86 static u32 *
nul_marshal(struct rpc_task * task,u32 * p,int ruid)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
nul_refresh(struct rpc_task * task)101 nul_refresh(struct rpc_task *task)
102 {
103 return task->tk_status = -EACCES;
104 }
105
106 static u32 *
nul_validate(struct rpc_task * task,u32 * p)107 nul_validate(struct rpc_task *task, u32 *p)
108 {
109 u32 n = ntohl(*p++);
110
111 if (n != RPC_AUTH_NULL) {
112 printk("RPC: bad verf flavor: %ld\n", (unsigned long) n);
113 return NULL;
114 }
115 if ((n = ntohl(*p++)) != 0) {
116 printk("RPC: bad verf size: %ld\n", (unsigned long) n);
117 return NULL;
118 }
119
120 return p;
121 }
122
123 struct rpc_authops authnull_ops = {
124 RPC_AUTH_NULL,
125 #ifdef RPC_DEBUG
126 "NULL",
127 #endif
128 nul_create,
129 nul_destroy,
130 nul_create_cred
131 };
132
133 static
134 struct rpc_credops null_credops = {
135 nul_destroy_cred,
136 nul_match,
137 nul_marshal,
138 nul_refresh,
139 nul_validate
140 };
141