Merge tag 'pm+acpi-4.3-rc1-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[deliverable/linux.git] / include / linux / sunrpc / auth.h
CommitLineData
1da177e4
LT
1/*
2 * linux/include/linux/sunrpc/auth.h
3 *
4 * Declarations for the RPC client authentication machinery.
5 *
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8
9#ifndef _LINUX_SUNRPC_AUTH_H
10#define _LINUX_SUNRPC_AUTH_H
11
12#ifdef __KERNEL__
13
1da177e4
LT
14#include <linux/sunrpc/sched.h>
15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/xdr.h>
17
60063497 18#include <linux/atomic.h>
31be5bf1 19#include <linux/rcupdate.h>
7eaf040b 20#include <linux/uidgid.h>
24a9a961 21#include <linux/utsname.h>
1da177e4 22
24a9a961
JL
23/*
24 * Size of the nodename buffer. RFC1831 specifies a hard limit of 255 bytes,
25 * but Linux hostnames are actually limited to __NEW_UTS_LEN bytes.
26 */
27#define UNX_MAXNODENAME __NEW_UTS_LEN
1da177e4 28
9568c5e9
CL
29struct rpcsec_gss_info;
30
4de6caa2
AA
31/* auth_cred ac_flags bits */
32enum {
33 RPC_CRED_NO_CRKEY_TIMEOUT = 0, /* underlying cred has no key timeout */
34 RPC_CRED_KEY_EXPIRE_SOON = 1, /* underlying cred key will expire soon */
35 RPC_CRED_NOTIFY_TIMEOUT = 2, /* nofity generic cred when underlying
36 key will expire soon */
37};
38
1da177e4
LT
39/* Work around the lack of a VFS credential */
40struct auth_cred {
7eaf040b
EB
41 kuid_t uid;
42 kgid_t gid;
1da177e4 43 struct group_info *group_info;
68c97153 44 const char *principal;
4de6caa2 45 unsigned long ac_flags;
7c67db3a 46 unsigned char machine_cred : 1;
1da177e4
LT
47};
48
49/*
50 * Client user credentials
51 */
4a8c1344
TM
52struct rpc_auth;
53struct rpc_credops;
1da177e4
LT
54struct rpc_cred {
55 struct hlist_node cr_hash; /* hash chain */
e092bdcd 56 struct list_head cr_lru; /* lru garbage collection */
31be5bf1 57 struct rcu_head cr_rcu;
4a8c1344 58 struct rpc_auth * cr_auth;
f1c0a861 59 const struct rpc_credops *cr_ops;
f895b252 60#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
1da177e4
LT
61 unsigned long cr_magic; /* 0x0f4aa4f0 */
62#endif
fc432dd9
TM
63 unsigned long cr_expire; /* when to gc */
64 unsigned long cr_flags; /* various flags */
65 atomic_t cr_count; /* ref count */
1da177e4 66
7eaf040b 67 kuid_t cr_uid;
1da177e4
LT
68
69 /* per-flavor data */
70};
fc432dd9
TM
71#define RPCAUTH_CRED_NEW 0
72#define RPCAUTH_CRED_UPTODATE 1
31be5bf1 73#define RPCAUTH_CRED_HASHED 2
126e216a 74#define RPCAUTH_CRED_NEGATIVE 3
1da177e4
LT
75
76#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0
77
78/*
79 * Client authentication handle
80 */
241269bd 81struct rpc_cred_cache;
4a8c1344 82struct rpc_authops;
1da177e4
LT
83struct rpc_auth {
84 unsigned int au_cslack; /* call cred size estimate */
24b2605b
BF
85 /* guess at number of u32's auth adds before
86 * reply data; normally the verifier size: */
87 unsigned int au_rslack;
88 /* for gss, used to calculate au_rslack: */
89 unsigned int au_verfsize;
90
1da177e4 91 unsigned int au_flags; /* various flags */
f1c0a861 92 const struct rpc_authops *au_ops; /* operations */
1da177e4
LT
93 rpc_authflavor_t au_flavor; /* pseudoflavor (note may
94 * differ from the flavor in
95 * au_ops->au_flavor in gss
96 * case) */
97 atomic_t au_count; /* Reference counter */
98
99 struct rpc_cred_cache * au_credcache;
100 /* per-flavor data */
101};
1da177e4 102
c2190661
TM
103struct rpc_auth_create_args {
104 rpc_authflavor_t pseudoflavor;
105 const char *target_name;
106};
107
8a317760
TM
108/* Flags for rpcauth_lookupcred() */
109#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */
bd956080 110#define RPCAUTH_LOOKUP_RCU 0x02 /* lock-less lookup */
8a317760 111
1da177e4
LT
112/*
113 * Client authentication ops
114 */
115struct rpc_authops {
116 struct module *owner;
117 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */
1da177e4 118 char * au_name;
c2190661 119 struct rpc_auth * (*create)(struct rpc_auth_create_args *, struct rpc_clnt *);
1da177e4
LT
120 void (*destroy)(struct rpc_auth *);
121
122 struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
123 struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int);
6a1a1e34 124 int (*list_pseudoflavors)(rpc_authflavor_t *, int);
9568c5e9 125 rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *);
a77c806f
CL
126 int (*flavor2info)(rpc_authflavor_t,
127 struct rpcsec_gss_info *);
4de6caa2
AA
128 int (*key_timeout)(struct rpc_auth *,
129 struct rpc_cred *);
1da177e4
LT
130};
131
132struct rpc_credops {
133 const char * cr_name; /* Name of the auth flavour */
fba3bad4 134 int (*cr_init)(struct rpc_auth *, struct rpc_cred *);
1da177e4
LT
135 void (*crdestroy)(struct rpc_cred *);
136
137 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
8572b8e2 138 struct rpc_cred * (*crbind)(struct rpc_task *, struct rpc_cred *, int);
d8ed029d 139 __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
1da177e4 140 int (*crrefresh)(struct rpc_task *);
d8ed029d 141 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
9f06c719 142 int (*crwrap_req)(struct rpc_task *, kxdreproc_t,
d8ed029d 143 void *, __be32 *, void *);
bf269551 144 int (*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
d8ed029d 145 void *, __be32 *, void *);
4de6caa2
AA
146 int (*crkey_timeout)(struct rpc_cred *);
147 bool (*crkey_to_expire)(struct rpc_cred *);
a0337d1d 148 char * (*crstringify_acceptor)(struct rpc_cred *);
1da177e4
LT
149};
150
f1c0a861
TM
151extern const struct rpc_authops authunix_ops;
152extern const struct rpc_authops authnull_ops;
1da177e4 153
5d8d9a4d
TM
154int __init rpc_init_authunix(void);
155int __init rpc_init_generic_auth(void);
156int __init rpcauth_init_module(void);
c135e84a
SR
157void rpcauth_remove_module(void);
158void rpc_destroy_generic_auth(void);
5d8d9a4d 159void rpc_destroy_authunix(void);
9499b434 160
9a559efd 161struct rpc_cred * rpc_lookup_cred(void);
bd956080 162struct rpc_cred * rpc_lookup_cred_nonblock(void);
68c97153 163struct rpc_cred * rpc_lookup_machine_cred(const char *service_name);
f1c0a861
TM
164int rpcauth_register(const struct rpc_authops *);
165int rpcauth_unregister(const struct rpc_authops *);
c2190661
TM
166struct rpc_auth * rpcauth_create(struct rpc_auth_create_args *,
167 struct rpc_clnt *);
de7a8ce3 168void rpcauth_release(struct rpc_auth *);
9568c5e9
CL
169rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t,
170 struct rpcsec_gss_info *);
a77c806f
CL
171int rpcauth_get_gssinfo(rpc_authflavor_t,
172 struct rpcsec_gss_info *);
6a1a1e34 173int rpcauth_list_flavors(rpc_authflavor_t *, int);
1da177e4 174struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int);
5fe4755e 175void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
1da177e4 176struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
8572b8e2 177struct rpc_cred * rpcauth_generic_bind_cred(struct rpc_task *, struct rpc_cred *, int);
1da177e4 178void put_rpccred(struct rpc_cred *);
d8ed029d
AD
179__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
180__be32 * rpcauth_checkverf(struct rpc_task *, __be32 *);
9f06c719 181int rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp, __be32 *data, void *obj);
bf269551 182int rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
1da177e4
LT
183int rpcauth_refreshcred(struct rpc_task *);
184void rpcauth_invalcred(struct rpc_task *);
185int rpcauth_uptodatecred(struct rpc_task *);
f5c2187c 186int rpcauth_init_credcache(struct rpc_auth *);
3ab9bb72
TM
187void rpcauth_destroy_credcache(struct rpc_auth *);
188void rpcauth_clear_credcache(struct rpc_cred_cache *);
4de6caa2
AA
189int rpcauth_key_timeout_notify(struct rpc_auth *,
190 struct rpc_cred *);
191bool rpcauth_cred_key_to_expire(struct rpc_cred *);
a0337d1d 192char * rpcauth_stringify_acceptor(struct rpc_cred *);
1da177e4
LT
193
194static inline
195struct rpc_cred * get_rpccred(struct rpc_cred *cred)
196{
197 atomic_inc(&cred->cr_count);
198 return cred;
199}
200
201#endif /* __KERNEL__ */
202#endif /* _LINUX_SUNRPC_AUTH_H */
This page took 1.22937 seconds and 5 git commands to generate.