8 #include <linux/slab.h>
9 #include <linux/types.h>
10 #include <linux/module.h>
11 #include <linux/sched.h>
14 #include <linux/sunrpc/debug.h>
18 # define RPCDBG_FACILITY RPCDBG_AUTH
21 #define RPC_MACHINE_CRED_USERID ((uid_t)0)
22 #define RPC_MACHINE_CRED_GROUPID ((gid_t)0)
29 static struct rpc_auth generic_auth;
30 static const struct rpc_credops generic_credops;
46 struct auth_cred acred = {
49 .principal = service_name,
53 dprintk(
"RPC: looking up machine cred for service %s\n",
55 return generic_auth.au_ops->lookup_cred(&generic_auth, &acred, 0);
59 static struct rpc_cred *generic_bind_cred(
struct rpc_task *
task,
60 struct rpc_cred *
cred,
int lookupflags)
65 return auth->au_ops->lookup_cred(auth, acred, lookupflags);
71 static struct rpc_cred *
72 generic_lookup_cred(
struct rpc_auth *auth,
struct auth_cred *acred,
int flags)
77 static struct rpc_cred *
78 generic_create_cred(
struct rpc_auth *auth,
struct auth_cred *acred,
int flags)
87 gcred->
gc_base.cr_flags = 1
UL << RPCAUTH_CRED_UPTODATE;
89 gcred->
acred.uid = acred->uid;
90 gcred->
acred.gid = acred->gid;
91 gcred->
acred.group_info = acred->group_info;
93 get_group_info(gcred->
acred.group_info);
94 gcred->
acred.machine_cred = acred->machine_cred;
95 gcred->
acred.principal = acred->principal;
97 dprintk(
"RPC: allocated %s cred %p for uid %d gid %d\n",
98 gcred->
acred.machine_cred ?
"machine" :
"generic",
99 gcred, acred->uid, acred->gid);
104 generic_free_cred(
struct rpc_cred *cred)
108 dprintk(
"RPC: generic_free_cred %p\n", gcred);
117 struct rpc_cred *cred =
container_of(head,
struct rpc_cred, cr_rcu);
118 generic_free_cred(cred);
122 generic_destroy_cred(
struct rpc_cred *cred)
124 call_rcu(&cred->cr_rcu, generic_free_cred_callback);
128 machine_cred_match(
struct auth_cred *acred,
struct generic_cred *gcred,
int flags)
130 if (!gcred->
acred.machine_cred ||
131 gcred->
acred.principal != acred->principal ||
132 gcred->
acred.uid != acred->uid ||
133 gcred->
acred.gid != acred->gid)
142 generic_match(
struct auth_cred *acred,
struct rpc_cred *cred,
int flags)
147 if (acred->machine_cred)
148 return machine_cred_match(acred, gcred, flags);
150 if (gcred->
acred.uid != acred->uid ||
151 gcred->
acred.gid != acred->gid ||
152 gcred->
acred.machine_cred != 0)
156 if (gcred->
acred.group_info == acred->group_info)
160 if (gcred->
acred.group_info->ngroups != acred->group_info->ngroups)
162 for (i = 0; i < gcred->
acred.group_info->ngroups; i++) {
183 static const struct rpc_authops generic_auth_ops = {
185 .au_name =
"Generic",
186 .lookup_cred = generic_lookup_cred,
187 .crcreate = generic_create_cred,
190 static struct rpc_auth generic_auth = {
191 .au_ops = &generic_auth_ops,
195 static const struct rpc_credops generic_credops = {
196 .cr_name =
"Generic cred",
197 .crdestroy = generic_destroy_cred,
198 .crbind = generic_bind_cred,
199 .crmatch = generic_match,