blob: a7cbb570cc5c98cb76fe0a8733a1c791bca7419b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/sunrpc/sched.h>
15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/xdr.h>
17
Arun Sharma600634972011-07-26 16:09:06 -070018#include <linux/atomic.h>
Trond Myklebust31be5bf2007-06-24 15:55:26 -040019#include <linux/rcupdate.h>
Eric W. Biederman7eaf0402013-02-01 16:31:17 -080020#include <linux/uidgid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22/* size of the nodename buffer */
23#define UNX_MAXNODENAME 32
24
Chuck Lever9568c5e2013-03-16 15:54:43 -040025struct rpcsec_gss_info;
26
Andy Adamson4de6caa2013-08-14 11:59:15 -040027/* auth_cred ac_flags bits */
28enum {
29 RPC_CRED_NO_CRKEY_TIMEOUT = 0, /* underlying cred has no key timeout */
30 RPC_CRED_KEY_EXPIRE_SOON = 1, /* underlying cred key will expire soon */
31 RPC_CRED_NOTIFY_TIMEOUT = 2, /* nofity generic cred when underlying
32 key will expire soon */
33};
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* Work around the lack of a VFS credential */
36struct auth_cred {
Eric W. Biederman7eaf0402013-02-01 16:31:17 -080037 kuid_t uid;
38 kgid_t gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 struct group_info *group_info;
Trond Myklebust68c97152012-01-03 13:22:46 -050040 const char *principal;
Andy Adamson4de6caa2013-08-14 11:59:15 -040041 unsigned long ac_flags;
Trond Myklebust7c67db32008-04-07 20:50:11 -040042 unsigned char machine_cred : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
45/*
46 * Client user credentials
47 */
Trond Myklebust4a8c1342007-06-07 10:14:14 -040048struct rpc_auth;
49struct rpc_credops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050struct rpc_cred {
51 struct hlist_node cr_hash; /* hash chain */
Trond Myklebuste092bdc2007-06-23 19:45:36 -040052 struct list_head cr_lru; /* lru garbage collection */
Trond Myklebust31be5bf2007-06-24 15:55:26 -040053 struct rcu_head cr_rcu;
Trond Myklebust4a8c1342007-06-07 10:14:14 -040054 struct rpc_auth * cr_auth;
Trond Myklebustf1c0a862007-06-23 20:17:58 -040055 const struct rpc_credops *cr_ops;
Jeff Laytonf895b252014-11-17 16:58:04 -050056#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 unsigned long cr_magic; /* 0x0f4aa4f0 */
58#endif
Trond Myklebustfc432dd2007-06-25 10:15:15 -040059 unsigned long cr_expire; /* when to gc */
60 unsigned long cr_flags; /* various flags */
61 atomic_t cr_count; /* ref count */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Eric W. Biederman7eaf0402013-02-01 16:31:17 -080063 kuid_t cr_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 /* per-flavor data */
66};
Trond Myklebustfc432dd2007-06-25 10:15:15 -040067#define RPCAUTH_CRED_NEW 0
68#define RPCAUTH_CRED_UPTODATE 1
Trond Myklebust31be5bf2007-06-24 15:55:26 -040069#define RPCAUTH_CRED_HASHED 2
Trond Myklebust126e2162010-05-13 12:55:38 -040070#define RPCAUTH_CRED_NEGATIVE 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72#define RPCAUTH_CRED_MAGIC 0x0f4aa4f0
73
74/*
75 * Client authentication handle
76 */
Trond Myklebust241269b2010-07-31 14:29:08 -040077struct rpc_cred_cache;
Trond Myklebust4a8c1342007-06-07 10:14:14 -040078struct rpc_authops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079struct rpc_auth {
80 unsigned int au_cslack; /* call cred size estimate */
J. Bruce Fields24b26052005-10-13 16:54:53 -040081 /* guess at number of u32's auth adds before
82 * reply data; normally the verifier size: */
83 unsigned int au_rslack;
84 /* for gss, used to calculate au_rslack: */
85 unsigned int au_verfsize;
86
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 unsigned int au_flags; /* various flags */
Trond Myklebustf1c0a862007-06-23 20:17:58 -040088 const struct rpc_authops *au_ops; /* operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 rpc_authflavor_t au_flavor; /* pseudoflavor (note may
90 * differ from the flavor in
91 * au_ops->au_flavor in gss
92 * case) */
93 atomic_t au_count; /* Reference counter */
94
95 struct rpc_cred_cache * au_credcache;
96 /* per-flavor data */
97};
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Trond Myklebustc2190662013-08-26 19:23:04 -040099struct rpc_auth_create_args {
100 rpc_authflavor_t pseudoflavor;
101 const char *target_name;
102};
103
Trond Myklebust8a317762006-02-01 12:18:36 -0500104/* Flags for rpcauth_lookupcred() */
105#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */
NeilBrownbd956082014-07-14 11:28:20 +1000106#define RPCAUTH_LOOKUP_RCU 0x02 /* lock-less lookup */
Trond Myklebust8a317762006-02-01 12:18:36 -0500107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/*
109 * Client authentication ops
110 */
111struct rpc_authops {
112 struct module *owner;
113 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 char * au_name;
Trond Myklebustc2190662013-08-26 19:23:04 -0400115 struct rpc_auth * (*create)(struct rpc_auth_create_args *, struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 void (*destroy)(struct rpc_auth *);
117
118 struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
119 struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int);
Chuck Lever6a1a1e32012-07-11 16:31:08 -0400120 int (*list_pseudoflavors)(rpc_authflavor_t *, int);
Chuck Lever9568c5e2013-03-16 15:54:43 -0400121 rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *);
Chuck Levera77c8062013-03-16 15:55:10 -0400122 int (*flavor2info)(rpc_authflavor_t,
123 struct rpcsec_gss_info *);
Andy Adamson4de6caa2013-08-14 11:59:15 -0400124 int (*key_timeout)(struct rpc_auth *,
125 struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126};
127
128struct rpc_credops {
129 const char * cr_name; /* Name of the auth flavour */
Trond Myklebustfba3bad2006-02-01 12:19:27 -0500130 int (*cr_init)(struct rpc_auth *, struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 void (*crdestroy)(struct rpc_cred *);
132
133 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
Trond Myklebust8572b8e2010-07-31 14:29:08 -0400134 struct rpc_cred * (*crbind)(struct rpc_task *, struct rpc_cred *, int);
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700135 __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 int (*crrefresh)(struct rpc_task *);
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700137 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
Chuck Lever9f06c712010-12-14 14:59:18 +0000138 int (*crwrap_req)(struct rpc_task *, kxdreproc_t,
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700139 void *, __be32 *, void *);
Chuck Leverbf269552010-12-14 14:59:29 +0000140 int (*crunwrap_resp)(struct rpc_task *, kxdrdproc_t,
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700141 void *, __be32 *, void *);
Andy Adamson4de6caa2013-08-14 11:59:15 -0400142 int (*crkey_timeout)(struct rpc_cred *);
143 bool (*crkey_to_expire)(struct rpc_cred *);
Jeff Laytona0337d12014-06-21 20:52:16 -0400144 char * (*crstringify_acceptor)(struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145};
146
Trond Myklebustf1c0a862007-06-23 20:17:58 -0400147extern const struct rpc_authops authunix_ops;
148extern const struct rpc_authops authnull_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400150int __init rpc_init_authunix(void);
151int __init rpc_init_generic_auth(void);
152int __init rpcauth_init_module(void);
Stephen Rothwellc135e842010-09-29 14:16:57 +1000153void rpcauth_remove_module(void);
154void rpc_destroy_generic_auth(void);
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400155void rpc_destroy_authunix(void);
Trond Myklebust9499b432007-06-24 15:57:57 -0400156
Trond Myklebust9a559ef2008-03-12 12:24:49 -0400157struct rpc_cred * rpc_lookup_cred(void);
NeilBrownbd956082014-07-14 11:28:20 +1000158struct rpc_cred * rpc_lookup_cred_nonblock(void);
Trond Myklebust68c97152012-01-03 13:22:46 -0500159struct rpc_cred * rpc_lookup_machine_cred(const char *service_name);
Trond Myklebustf1c0a862007-06-23 20:17:58 -0400160int rpcauth_register(const struct rpc_authops *);
161int rpcauth_unregister(const struct rpc_authops *);
Trond Myklebustc2190662013-08-26 19:23:04 -0400162struct rpc_auth * rpcauth_create(struct rpc_auth_create_args *,
163 struct rpc_clnt *);
Trond Myklebustde7a8ce2007-06-23 10:46:47 -0400164void rpcauth_release(struct rpc_auth *);
Chuck Lever9568c5e2013-03-16 15:54:43 -0400165rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t,
166 struct rpcsec_gss_info *);
Chuck Levera77c8062013-03-16 15:55:10 -0400167int rpcauth_get_gssinfo(rpc_authflavor_t,
168 struct rpcsec_gss_info *);
Chuck Lever6a1a1e32012-07-11 16:31:08 -0400169int rpcauth_list_flavors(rpc_authflavor_t *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int);
Trond Myklebust5fe47552007-06-23 19:55:31 -0400171void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
Trond Myklebust8572b8e2010-07-31 14:29:08 -0400173struct rpc_cred * rpcauth_generic_bind_cred(struct rpc_task *, struct rpc_cred *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174void put_rpccred(struct rpc_cred *);
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700175__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
176__be32 * rpcauth_checkverf(struct rpc_task *, __be32 *);
Chuck Lever9f06c712010-12-14 14:59:18 +0000177int rpcauth_wrap_req(struct rpc_task *task, kxdreproc_t encode, void *rqstp, __be32 *data, void *obj);
Chuck Leverbf269552010-12-14 14:59:29 +0000178int rpcauth_unwrap_resp(struct rpc_task *task, kxdrdproc_t decode, void *rqstp, __be32 *data, void *obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179int rpcauth_refreshcred(struct rpc_task *);
180void rpcauth_invalcred(struct rpc_task *);
181int rpcauth_uptodatecred(struct rpc_task *);
Trond Myklebustf5c21872007-06-25 17:11:20 -0400182int rpcauth_init_credcache(struct rpc_auth *);
Trond Myklebust3ab9bb72007-06-09 15:41:42 -0400183void rpcauth_destroy_credcache(struct rpc_auth *);
184void rpcauth_clear_credcache(struct rpc_cred_cache *);
Andy Adamson4de6caa2013-08-14 11:59:15 -0400185int rpcauth_key_timeout_notify(struct rpc_auth *,
186 struct rpc_cred *);
187bool rpcauth_cred_key_to_expire(struct rpc_cred *);
Jeff Laytona0337d12014-06-21 20:52:16 -0400188char * rpcauth_stringify_acceptor(struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190static inline
191struct rpc_cred * get_rpccred(struct rpc_cred *cred)
192{
193 atomic_inc(&cred->cr_count);
194 return cred;
195}
196
197#endif /* __KERNEL__ */
198#endif /* _LINUX_SUNRPC_AUTH_H */