1
2
3
4
5
6
7
8
9#ifndef _LINUX_SUNRPC_AUTH_H
10#define _LINUX_SUNRPC_AUTH_H
11
12#ifdef __KERNEL__
13
14#include <linux/sunrpc/sched.h>
15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/xdr.h>
17
18#include <linux/atomic.h>
19#include <linux/rcupdate.h>
20#include <linux/uidgid.h>
21#include <linux/utsname.h>
22
23
24
25
26
27#define UNX_MAXNODENAME __NEW_UTS_LEN
28
29struct rpcsec_gss_info;
30
31
32enum {
33 RPC_CRED_KEY_EXPIRE_SOON = 1,
34 RPC_CRED_NOTIFY_TIMEOUT = 2,
35
36};
37
38
39struct auth_cred {
40 kuid_t uid;
41 kgid_t gid;
42 struct group_info *group_info;
43 const char *principal;
44 unsigned long ac_flags;
45 unsigned char machine_cred : 1;
46};
47
48
49
50
51struct rpc_auth;
52struct rpc_credops;
53struct rpc_cred {
54 struct hlist_node cr_hash;
55 struct list_head cr_lru;
56 struct rcu_head cr_rcu;
57 struct rpc_auth * cr_auth;
58 const struct rpc_credops *cr_ops;
59#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
60 unsigned long cr_magic;
61#endif
62 unsigned long cr_expire;
63 unsigned long cr_flags;
64 atomic_t cr_count;
65
66 kuid_t cr_uid;
67
68
69};
70#define RPCAUTH_CRED_NEW 0
71#define RPCAUTH_CRED_UPTODATE 1
72#define RPCAUTH_CRED_HASHED 2
73#define RPCAUTH_CRED_NEGATIVE 3
74
75#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0
76
77
78#define RPCAUTH_AUTH_NO_CRKEY_TIMEOUT 0x0001
79
80
81
82
83struct rpc_cred_cache;
84struct rpc_authops;
85struct rpc_auth {
86 unsigned int au_cslack;
87
88
89 unsigned int au_rslack;
90
91 unsigned int au_verfsize;
92
93 unsigned int au_flags;
94 const struct rpc_authops *au_ops;
95 rpc_authflavor_t au_flavor;
96
97
98
99 atomic_t au_count;
100
101 struct rpc_cred_cache * au_credcache;
102
103};
104
105
106#define RPCAUTH_AUTH_DATATOUCH 0x00000002
107
108struct rpc_auth_create_args {
109 rpc_authflavor_t pseudoflavor;
110 const char *target_name;
111};
112
113
114#define RPCAUTH_LOOKUP_NEW 0x01
115#define RPCAUTH_LOOKUP_RCU 0x02
116
117
118
119
120struct rpc_authops {
121 struct module *owner;
122 rpc_authflavor_t au_flavor;
123 char * au_name;
124 struct rpc_auth * (*create)(struct rpc_auth_create_args *, struct rpc_clnt *);
125 void (*destroy)(struct rpc_auth *);
126
127 int (*hash_cred)(struct auth_cred *, unsigned int);
128 struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
129 struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t);
130 int (*list_pseudoflavors)(rpc_authflavor_t *, int);
131 rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *);
132 int (*flavor2info)(rpc_authflavor_t,
133 struct rpcsec_gss_info *);
134 int (*key_timeout)(struct rpc_auth *,
135 struct rpc_cred *);
136};
137
138struct rpc_credops {
139 const char * cr_name;
140 int (*cr_init)(struct rpc_auth *, struct rpc_cred *);
141 void (*crdestroy)(struct rpc_cred *);
142
143 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
144 struct rpc_cred * (*crbind)(struct rpc_task *, struct rpc_cred *, int);
145 __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
146 int (*crrefresh)(struct rpc_task *);
147 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
148 int (*crwrap_req)(struct rpc_task *, kxdreproc_t,
149 void *, __be32 *, void *);
150 int (*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
151 void *, __be32 *, void *);
152 int (*crkey_timeout)(struct rpc_cred *);
153 bool (*crkey_to_expire)(struct rpc_cred *);
154 char * (*crstringify_acceptor)(struct rpc_cred *);
155};
156
157extern const struct rpc_authops authunix_ops;
158extern const struct rpc_authops authnull_ops;
159
160int __init rpc_init_authunix(void);
161int __init rpc_init_generic_auth(void);
162int __init rpcauth_init_module(void);
163void rpcauth_remove_module(void);
164void rpc_destroy_generic_auth(void);
165void rpc_destroy_authunix(void);
166
167struct rpc_cred * rpc_lookup_cred(void);
168struct rpc_cred * rpc_lookup_cred_nonblock(void);
169struct rpc_cred * rpc_lookup_generic_cred(struct auth_cred *, int, gfp_t);
170struct rpc_cred * rpc_lookup_machine_cred(const char *service_name);
171int rpcauth_register(const struct rpc_authops *);
172int rpcauth_unregister(const struct rpc_authops *);
173struct rpc_auth * rpcauth_create(struct rpc_auth_create_args *,
174 struct rpc_clnt *);
175void rpcauth_release(struct rpc_auth *);
176rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t,
177 struct rpcsec_gss_info *);
178int rpcauth_get_gssinfo(rpc_authflavor_t,
179 struct rpcsec_gss_info *);
180int rpcauth_list_flavors(rpc_authflavor_t *, int);
181struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t);
182void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
183struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
184struct rpc_cred * rpcauth_generic_bind_cred(struct rpc_task *, struct rpc_cred *, int);
185void put_rpccred(struct rpc_cred *);
186__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
187__be32 * rpcauth_checkverf(struct rpc_task *, __be32 *);
188int rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp, __be32 *data, void *obj);
189int rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
190int rpcauth_refreshcred(struct rpc_task *);
191void rpcauth_invalcred(struct rpc_task *);
192int rpcauth_uptodatecred(struct rpc_task *);
193int rpcauth_init_credcache(struct rpc_auth *);
194void rpcauth_destroy_credcache(struct rpc_auth *);
195void rpcauth_clear_credcache(struct rpc_cred_cache *);
196int rpcauth_key_timeout_notify(struct rpc_auth *,
197 struct rpc_cred *);
198bool rpcauth_cred_key_to_expire(struct rpc_auth *, struct rpc_cred *);
199char * rpcauth_stringify_acceptor(struct rpc_cred *);
200
201static inline
202struct rpc_cred * get_rpccred(struct rpc_cred *cred)
203{
204 if (cred != NULL)
205 atomic_inc(&cred->cr_count);
206 return cred;
207}
208
209
210
211
212
213
214
215
216
217
218
219static inline struct rpc_cred *
220get_rpccred_rcu(struct rpc_cred *cred)
221{
222 if (atomic_inc_not_zero(&cred->cr_count))
223 return cred;
224 return NULL;
225}
226
227#endif
228#endif
229