9 #include <linux/slab.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/module.h>
17 #define NFS_NGROUPS 16
24 #define uc_uid uc_base.cr_uid
26 #define UNX_WRITESLACK (21 + (UNX_MAXNODENAME >> 2))
29 # define RPCDBG_FACILITY RPCDBG_AUTH
32 static struct rpc_auth unix_auth;
33 static const struct rpc_credops unix_credops;
35 static struct rpc_auth *
36 unx_create(
struct rpc_clnt *clnt, rpc_authflavor_t flavor)
38 dprintk(
"RPC: creating UNIX authenticator for client %p\n",
45 unx_destroy(
struct rpc_auth *
auth)
47 dprintk(
"RPC: destroying UNIX authenticator %p\n", auth);
54 static struct rpc_cred *
55 unx_lookup_cred(
struct rpc_auth *
auth,
struct auth_cred *acred,
int flags)
60 static struct rpc_cred *
61 unx_create_cred(
struct rpc_auth *
auth,
struct auth_cred *acred,
int flags)
64 unsigned int groups = 0;
67 dprintk(
"RPC: allocating UNIX cred for uid %d gid %d\n",
68 acred->uid, acred->gid);
74 cred->
uc_base.cr_flags = 1
UL << RPCAUTH_CRED_UPTODATE;
76 if (acred->group_info !=
NULL)
77 groups = acred->group_info->ngroups;
82 for (i = 0; i < groups; i++) {
96 dprintk(
"RPC: unx_free_cred %p\n", unx_cred);
104 unx_free_cred(unx_cred);
108 unx_destroy_cred(
struct rpc_cred *cred)
110 call_rcu(&cred->cr_rcu, unx_free_cred_callback);
119 unx_match(
struct auth_cred *acred,
struct rpc_cred *rcred,
int flags)
122 unsigned int groups = 0;
126 if (cred->uc_uid != acred->uid || cred->
uc_gid != acred->gid)
129 if (acred->group_info !=
NULL)
130 groups = acred->group_info->ngroups;
133 for (i = 0; i < groups ; i++) {
157 *p++ =
htonl(RPC_AUTH_UNIX);
171 *hold =
htonl(p - hold - 1);
172 *base =
htonl((p - base - 1) << 2);
174 *p++ =
htonl(RPC_AUTH_NULL);
193 rpc_authflavor_t flavor;
196 flavor =
ntohl(*p++);
197 if (flavor != RPC_AUTH_NULL &&
198 flavor != RPC_AUTH_UNIX &&
199 flavor != RPC_AUTH_SHORT) {
200 printk(
"RPC: bad verf flavor: %u\n", flavor);
205 if (size > RPC_MAX_AUTH_SIZE) {
206 printk(
"RPC: giant verf size: %u\n", size);
209 task->
tk_rqstp->rq_cred->cr_auth->au_rslack = (size >> 2) + 2;
227 .au_flavor = RPC_AUTH_UNIX,
229 .create = unx_create,
230 .destroy = unx_destroy,
231 .lookup_cred = unx_lookup_cred,
232 .crcreate = unx_create_cred,
236 struct rpc_auth unix_auth = {
240 .au_flavor = RPC_AUTH_UNIX,
245 const struct rpc_credops unix_credops = {
246 .cr_name =
"AUTH_UNIX",
247 .crdestroy = unx_destroy_cred,
249 .crmatch = unx_match,
250 .crmarshal = unx_marshal,
251 .crrefresh = unx_refresh,
252 .crvalidate = unx_validate,