Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/include/linux/sunrpc/auth.h |
| 4 | * |
| 5 | * Declarations for the RPC client authentication machinery. |
| 6 | * |
| 7 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 8 | */ |
| 9 | |
| 10 | #ifndef _LINUX_SUNRPC_AUTH_H |
| 11 | #define _LINUX_SUNRPC_AUTH_H |
| 12 | |
| 13 | #ifdef __KERNEL__ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sunrpc/sched.h> |
| 16 | #include <linux/sunrpc/msg_prot.h> |
| 17 | #include <linux/sunrpc/xdr.h> |
| 18 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 19 | #include <linux/atomic.h> |
Trond Myklebust | 31be5bf | 2007-06-24 15:55:26 -0400 | [diff] [blame] | 20 | #include <linux/rcupdate.h> |
Eric W. Biederman | 7eaf040 | 2013-02-01 16:31:17 -0800 | [diff] [blame] | 21 | #include <linux/uidgid.h> |
Jeff Layton | 24a9a96 | 2015-08-03 07:44:53 -0400 | [diff] [blame] | 22 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Jeff Layton | 24a9a96 | 2015-08-03 07:44:53 -0400 | [diff] [blame] | 24 | /* |
Chuck Lever | 4500632 | 2016-03-01 13:06:02 -0500 | [diff] [blame] | 25 | * Maximum size of AUTH_NONE authentication information, in XDR words. |
| 26 | */ |
| 27 | #define NUL_CALLSLACK (4) |
| 28 | #define NUL_REPLYSLACK (2) |
| 29 | |
| 30 | /* |
Jeff Layton | 24a9a96 | 2015-08-03 07:44:53 -0400 | [diff] [blame] | 31 | * Size of the nodename buffer. RFC1831 specifies a hard limit of 255 bytes, |
| 32 | * but Linux hostnames are actually limited to __NEW_UTS_LEN bytes. |
| 33 | */ |
| 34 | #define UNX_MAXNODENAME __NEW_UTS_LEN |
Chuck Lever | 4500632 | 2016-03-01 13:06:02 -0500 | [diff] [blame] | 35 | #define UNX_CALLSLACK (21 + XDR_QUADLEN(UNX_MAXNODENAME)) |
Kinglong Mee | 5786461 | 2017-02-07 21:48:11 +0800 | [diff] [blame] | 36 | #define UNX_NGROUPS 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Chuck Lever | 9568c5e | 2013-03-16 15:54:43 -0400 | [diff] [blame] | 38 | struct rpcsec_gss_info; |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct auth_cred { |
NeilBrown | 97f68c6b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 41 | const struct cred *cred; |
NeilBrown | 1a80810 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 42 | const char *principal; /* If present, this is a machine credential */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | /* |
| 46 | * Client user credentials |
| 47 | */ |
Trond Myklebust | 4a8c134 | 2007-06-07 10:14:14 -0400 | [diff] [blame] | 48 | struct rpc_auth; |
| 49 | struct rpc_credops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct rpc_cred { |
| 51 | struct hlist_node cr_hash; /* hash chain */ |
Trond Myklebust | e092bdc | 2007-06-23 19:45:36 -0400 | [diff] [blame] | 52 | struct list_head cr_lru; /* lru garbage collection */ |
Trond Myklebust | 31be5bf | 2007-06-24 15:55:26 -0400 | [diff] [blame] | 53 | struct rcu_head cr_rcu; |
Trond Myklebust | 4a8c134 | 2007-06-07 10:14:14 -0400 | [diff] [blame] | 54 | struct rpc_auth * cr_auth; |
Trond Myklebust | f1c0a86 | 2007-06-23 20:17:58 -0400 | [diff] [blame] | 55 | const struct rpc_credops *cr_ops; |
Trond Myklebust | fc432dd | 2007-06-25 10:15:15 -0400 | [diff] [blame] | 56 | unsigned long cr_expire; /* when to gc */ |
| 57 | unsigned long cr_flags; /* various flags */ |
Trond Myklebust | 79b1818 | 2018-10-14 10:34:31 -0400 | [diff] [blame] | 58 | refcount_t cr_count; /* ref count */ |
NeilBrown | 97f68c6b | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 59 | const struct cred *cr_cred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* per-flavor data */ |
| 62 | }; |
Trond Myklebust | fc432dd | 2007-06-25 10:15:15 -0400 | [diff] [blame] | 63 | #define RPCAUTH_CRED_NEW 0 |
| 64 | #define RPCAUTH_CRED_UPTODATE 1 |
Trond Myklebust | 31be5bf | 2007-06-24 15:55:26 -0400 | [diff] [blame] | 65 | #define RPCAUTH_CRED_HASHED 2 |
Trond Myklebust | 126e216 | 2010-05-13 12:55:38 -0400 | [diff] [blame] | 66 | #define RPCAUTH_CRED_NEGATIVE 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
NeilBrown | a52458b | 2018-12-03 11:30:31 +1100 | [diff] [blame] | 68 | const struct cred *rpc_machine_cred(void); |
NeilBrown | 5e16923 | 2018-12-03 11:30:30 +1100 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Client authentication handle |
| 72 | */ |
Trond Myklebust | 241269b | 2010-07-31 14:29:08 -0400 | [diff] [blame] | 73 | struct rpc_cred_cache; |
Trond Myklebust | 4a8c134 | 2007-06-07 10:14:14 -0400 | [diff] [blame] | 74 | struct rpc_authops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | struct rpc_auth { |
| 76 | unsigned int au_cslack; /* call cred size estimate */ |
Chuck Lever | 35e77d2 | 2019-02-11 11:25:36 -0500 | [diff] [blame] | 77 | unsigned int au_rslack; /* reply cred size estimate */ |
Chuck Lever | a00275b | 2019-02-11 11:25:31 -0500 | [diff] [blame] | 78 | unsigned int au_verfsize; /* size of reply verifier */ |
Chuck Lever | 35e77d2 | 2019-02-11 11:25:36 -0500 | [diff] [blame] | 79 | unsigned int au_ralign; /* words before UL header */ |
J. Bruce Fields | 24b2605 | 2005-10-13 16:54:53 -0400 | [diff] [blame] | 80 | |
Chuck Lever | 35e77d2 | 2019-02-11 11:25:36 -0500 | [diff] [blame] | 81 | unsigned int au_flags; |
| 82 | const struct rpc_authops *au_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | rpc_authflavor_t au_flavor; /* pseudoflavor (note may |
| 84 | * differ from the flavor in |
| 85 | * au_ops->au_flavor in gss |
| 86 | * case) */ |
Trond Myklebust | 331bc71 | 2018-10-14 10:40:29 -0400 | [diff] [blame] | 87 | refcount_t au_count; /* Reference counter */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
| 89 | struct rpc_cred_cache * au_credcache; |
| 90 | /* per-flavor data */ |
| 91 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
Chuck Lever | 65b8017 | 2016-06-29 13:55:06 -0400 | [diff] [blame] | 93 | /* rpc_auth au_flags */ |
| 94 | #define RPCAUTH_AUTH_DATATOUCH 0x00000002 |
| 95 | |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 96 | struct rpc_auth_create_args { |
| 97 | rpc_authflavor_t pseudoflavor; |
| 98 | const char *target_name; |
| 99 | }; |
| 100 | |
Trond Myklebust | 8a31776 | 2006-02-01 12:18:36 -0500 | [diff] [blame] | 101 | /* Flags for rpcauth_lookupcred() */ |
| 102 | #define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */ |
Trond Myklebust | 8a31776 | 2006-02-01 12:18:36 -0500 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Client authentication ops |
| 106 | */ |
| 107 | struct rpc_authops { |
| 108 | struct module *owner; |
| 109 | rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | char * au_name; |
Sargun Dhillon | 82b98ca | 2018-07-05 16:48:50 +0000 | [diff] [blame] | 111 | struct rpc_auth * (*create)(const struct rpc_auth_create_args *, |
| 112 | struct rpc_clnt *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | void (*destroy)(struct rpc_auth *); |
| 114 | |
Frank Sorenson | e856a23 | 2016-09-29 10:44:37 -0500 | [diff] [blame] | 115 | int (*hash_cred)(struct auth_cred *, unsigned int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int); |
Jeff Layton | 3c6e0bc | 2016-04-21 20:51:54 -0400 | [diff] [blame] | 117 | struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t); |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 118 | int (*list_pseudoflavors)(rpc_authflavor_t *, int); |
Chuck Lever | 9568c5e | 2013-03-16 15:54:43 -0400 | [diff] [blame] | 119 | rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *); |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 120 | int (*flavor2info)(rpc_authflavor_t, |
| 121 | struct rpcsec_gss_info *); |
Andy Adamson | 4de6caa | 2013-08-14 11:59:15 -0400 | [diff] [blame] | 122 | int (*key_timeout)(struct rpc_auth *, |
| 123 | struct rpc_cred *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | struct rpc_credops { |
| 127 | const char * cr_name; /* Name of the auth flavour */ |
Trond Myklebust | fba3bad | 2006-02-01 12:19:27 -0500 | [diff] [blame] | 128 | int (*cr_init)(struct rpc_auth *, struct rpc_cred *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | void (*crdestroy)(struct rpc_cred *); |
| 130 | |
| 131 | int (*crmatch)(struct auth_cred *, struct rpc_cred *, int); |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 132 | int (*crmarshal)(struct rpc_task *task, |
| 133 | struct xdr_stream *xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | int (*crrefresh)(struct rpc_task *); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 135 | int (*crvalidate)(struct rpc_task *task, |
| 136 | struct xdr_stream *xdr); |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 137 | int (*crwrap_req)(struct rpc_task *task, |
| 138 | struct xdr_stream *xdr); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 139 | int (*crunwrap_resp)(struct rpc_task *task, |
| 140 | struct xdr_stream *xdr); |
Andy Adamson | 4de6caa | 2013-08-14 11:59:15 -0400 | [diff] [blame] | 141 | int (*crkey_timeout)(struct rpc_cred *); |
Jeff Layton | a0337d1 | 2014-06-21 20:52:16 -0400 | [diff] [blame] | 142 | char * (*crstringify_acceptor)(struct rpc_cred *); |
Trond Myklebust | 3021a5bb | 2018-08-14 13:50:21 -0400 | [diff] [blame] | 143 | bool (*crneed_reencode)(struct rpc_task *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Trond Myklebust | f1c0a86 | 2007-06-23 20:17:58 -0400 | [diff] [blame] | 146 | extern const struct rpc_authops authunix_ops; |
| 147 | extern const struct rpc_authops authnull_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Trond Myklebust | 5d8d9a4 | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 149 | int __init rpc_init_authunix(void); |
Trond Myklebust | 5d8d9a4 | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 150 | int __init rpcauth_init_module(void); |
Stephen Rothwell | c135e84 | 2010-09-29 14:16:57 +1000 | [diff] [blame] | 151 | void rpcauth_remove_module(void); |
Trond Myklebust | 5d8d9a4 | 2010-07-31 14:29:07 -0400 | [diff] [blame] | 152 | void rpc_destroy_authunix(void); |
Trond Myklebust | 9499b43 | 2007-06-24 15:57:57 -0400 | [diff] [blame] | 153 | |
Trond Myklebust | f1c0a86 | 2007-06-23 20:17:58 -0400 | [diff] [blame] | 154 | int rpcauth_register(const struct rpc_authops *); |
| 155 | int rpcauth_unregister(const struct rpc_authops *); |
Sargun Dhillon | 82b98ca | 2018-07-05 16:48:50 +0000 | [diff] [blame] | 156 | struct rpc_auth * rpcauth_create(const struct rpc_auth_create_args *, |
Trond Myklebust | c219066 | 2013-08-26 19:23:04 -0400 | [diff] [blame] | 157 | struct rpc_clnt *); |
Trond Myklebust | de7a8ce | 2007-06-23 10:46:47 -0400 | [diff] [blame] | 158 | void rpcauth_release(struct rpc_auth *); |
Chuck Lever | 9568c5e | 2013-03-16 15:54:43 -0400 | [diff] [blame] | 159 | rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t, |
| 160 | struct rpcsec_gss_info *); |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 161 | int rpcauth_get_gssinfo(rpc_authflavor_t, |
| 162 | struct rpcsec_gss_info *); |
Chuck Lever | 6a1a1e3 | 2012-07-11 16:31:08 -0400 | [diff] [blame] | 163 | int rpcauth_list_flavors(rpc_authflavor_t *, int); |
Jeff Layton | 3c6e0bc | 2016-04-21 20:51:54 -0400 | [diff] [blame] | 164 | struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t); |
Trond Myklebust | 5fe4755 | 2007-06-23 19:55:31 -0400 | [diff] [blame] | 165 | void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | void put_rpccred(struct rpc_cred *); |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 168 | int rpcauth_marshcred(struct rpc_task *task, |
| 169 | struct xdr_stream *xdr); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 170 | int rpcauth_checkverf(struct rpc_task *task, |
| 171 | struct xdr_stream *xdr); |
Chuck Lever | e8680a2 | 2019-02-11 11:24:48 -0500 | [diff] [blame] | 172 | int rpcauth_wrap_req_encode(struct rpc_task *task, |
| 173 | struct xdr_stream *xdr); |
| 174 | int rpcauth_wrap_req(struct rpc_task *task, |
| 175 | struct xdr_stream *xdr); |
Chuck Lever | a0584ee | 2019-02-11 11:24:58 -0500 | [diff] [blame] | 176 | int rpcauth_unwrap_resp_decode(struct rpc_task *task, |
| 177 | struct xdr_stream *xdr); |
| 178 | int rpcauth_unwrap_resp(struct rpc_task *task, |
| 179 | struct xdr_stream *xdr); |
Trond Myklebust | 3021a5bb | 2018-08-14 13:50:21 -0400 | [diff] [blame] | 180 | bool rpcauth_xmit_need_reencode(struct rpc_task *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | int rpcauth_refreshcred(struct rpc_task *); |
| 182 | void rpcauth_invalcred(struct rpc_task *); |
| 183 | int rpcauth_uptodatecred(struct rpc_task *); |
Trond Myklebust | f5c2187 | 2007-06-25 17:11:20 -0400 | [diff] [blame] | 184 | int rpcauth_init_credcache(struct rpc_auth *); |
Trond Myklebust | 3ab9bb7 | 2007-06-09 15:41:42 -0400 | [diff] [blame] | 185 | void rpcauth_destroy_credcache(struct rpc_auth *); |
| 186 | void rpcauth_clear_credcache(struct rpc_cred_cache *); |
Jeff Layton | a0337d1 | 2014-06-21 20:52:16 -0400 | [diff] [blame] | 187 | char * rpcauth_stringify_acceptor(struct rpc_cred *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | static inline |
Trond Myklebust | 07d02a6 | 2018-10-12 13:28:26 -0400 | [diff] [blame] | 190 | struct rpc_cred *get_rpccred(struct rpc_cred *cred) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
Trond Myklebust | 79b1818 | 2018-10-14 10:34:31 -0400 | [diff] [blame] | 192 | if (cred != NULL && refcount_inc_not_zero(&cred->cr_count)) |
Trond Myklebust | 07d02a6 | 2018-10-12 13:28:26 -0400 | [diff] [blame] | 193 | return cred; |
| 194 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | #endif /* __KERNEL__ */ |
| 198 | #endif /* _LINUX_SUNRPC_AUTH_H */ |