blob: 359dfdd04e7788a6926d7e278db94dd166e3da09 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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 Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/sunrpc/sched.h>
16#include <linux/sunrpc/msg_prot.h>
17#include <linux/sunrpc/xdr.h>
18
Arun Sharma600634972011-07-26 16:09:06 -070019#include <linux/atomic.h>
Trond Myklebust31be5bf2007-06-24 15:55:26 -040020#include <linux/rcupdate.h>
Eric W. Biederman7eaf0402013-02-01 16:31:17 -080021#include <linux/uidgid.h>
Jeff Layton24a9a962015-08-03 07:44:53 -040022#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Jeff Layton24a9a962015-08-03 07:44:53 -040024/*
Chuck Lever45006322016-03-01 13:06:02 -050025 * Maximum size of AUTH_NONE authentication information, in XDR words.
26 */
27#define NUL_CALLSLACK (4)
28#define NUL_REPLYSLACK (2)
29
30/*
Jeff Layton24a9a962015-08-03 07:44:53 -040031 * 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 Lever45006322016-03-01 13:06:02 -050035#define UNX_CALLSLACK (21 + XDR_QUADLEN(UNX_MAXNODENAME))
Kinglong Mee57864612017-02-07 21:48:11 +080036#define UNX_NGROUPS 16
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Chuck Lever9568c5e2013-03-16 15:54:43 -040038struct rpcsec_gss_info;
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040struct auth_cred {
NeilBrown97f68c6b2018-12-03 11:30:30 +110041 const struct cred *cred;
NeilBrown1a808102018-12-03 11:30:30 +110042 const char *principal; /* If present, this is a machine credential */
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;
Trond Myklebustfc432dd2007-06-25 10:15:15 -040056 unsigned long cr_expire; /* when to gc */
57 unsigned long cr_flags; /* various flags */
Trond Myklebust79b18182018-10-14 10:34:31 -040058 refcount_t cr_count; /* ref count */
NeilBrown97f68c6b2018-12-03 11:30:30 +110059 const struct cred *cr_cred;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 /* per-flavor data */
62};
Trond Myklebustfc432dd2007-06-25 10:15:15 -040063#define RPCAUTH_CRED_NEW 0
64#define RPCAUTH_CRED_UPTODATE 1
Trond Myklebust31be5bf2007-06-24 15:55:26 -040065#define RPCAUTH_CRED_HASHED 2
Trond Myklebust126e2162010-05-13 12:55:38 -040066#define RPCAUTH_CRED_NEGATIVE 3
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
NeilBrowna52458b2018-12-03 11:30:31 +110068const struct cred *rpc_machine_cred(void);
NeilBrown5e169232018-12-03 11:30:30 +110069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
71 * Client authentication handle
72 */
Trond Myklebust241269b2010-07-31 14:29:08 -040073struct rpc_cred_cache;
Trond Myklebust4a8c1342007-06-07 10:14:14 -040074struct rpc_authops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075struct rpc_auth {
76 unsigned int au_cslack; /* call cred size estimate */
J. Bruce Fields24b26052005-10-13 16:54:53 -040077 /* guess at number of u32's auth adds before
78 * reply data; normally the verifier size: */
79 unsigned int au_rslack;
Chuck Levera00275b2019-02-11 11:25:31 -050080 unsigned int au_verfsize; /* size of reply verifier */
J. Bruce Fields24b26052005-10-13 16:54:53 -040081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 unsigned int au_flags; /* various flags */
Trond Myklebustf1c0a862007-06-23 20:17:58 -040083 const struct rpc_authops *au_ops; /* operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 rpc_authflavor_t au_flavor; /* pseudoflavor (note may
85 * differ from the flavor in
86 * au_ops->au_flavor in gss
87 * case) */
Trond Myklebust331bc712018-10-14 10:40:29 -040088 refcount_t au_count; /* Reference counter */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 struct rpc_cred_cache * au_credcache;
91 /* per-flavor data */
92};
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Chuck Lever65b80172016-06-29 13:55:06 -040094/* rpc_auth au_flags */
95#define RPCAUTH_AUTH_DATATOUCH 0x00000002
96
Trond Myklebustc2190662013-08-26 19:23:04 -040097struct rpc_auth_create_args {
98 rpc_authflavor_t pseudoflavor;
99 const char *target_name;
100};
101
Trond Myklebust8a317762006-02-01 12:18:36 -0500102/* Flags for rpcauth_lookupcred() */
103#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */
Trond Myklebust8a317762006-02-01 12:18:36 -0500104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/*
106 * Client authentication ops
107 */
108struct rpc_authops {
109 struct module *owner;
110 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 char * au_name;
Sargun Dhillon82b98ca2018-07-05 16:48:50 +0000112 struct rpc_auth * (*create)(const struct rpc_auth_create_args *,
113 struct rpc_clnt *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 void (*destroy)(struct rpc_auth *);
115
Frank Sorensone856a232016-09-29 10:44:37 -0500116 int (*hash_cred)(struct auth_cred *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
Jeff Layton3c6e0bc2016-04-21 20:51:54 -0400118 struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t);
Chuck Lever6a1a1e32012-07-11 16:31:08 -0400119 int (*list_pseudoflavors)(rpc_authflavor_t *, int);
Chuck Lever9568c5e2013-03-16 15:54:43 -0400120 rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *);
Chuck Levera77c8062013-03-16 15:55:10 -0400121 int (*flavor2info)(rpc_authflavor_t,
122 struct rpcsec_gss_info *);
Andy Adamson4de6caa2013-08-14 11:59:15 -0400123 int (*key_timeout)(struct rpc_auth *,
124 struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125};
126
127struct rpc_credops {
128 const char * cr_name; /* Name of the auth flavour */
Trond Myklebustfba3bad2006-02-01 12:19:27 -0500129 int (*cr_init)(struct rpc_auth *, struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 void (*crdestroy)(struct rpc_cred *);
131
132 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
Chuck Levere8680a22019-02-11 11:24:48 -0500133 int (*crmarshal)(struct rpc_task *task,
134 struct xdr_stream *xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 int (*crrefresh)(struct rpc_task *);
Chuck Levera0584ee2019-02-11 11:24:58 -0500136 int (*crvalidate)(struct rpc_task *task,
137 struct xdr_stream *xdr);
Chuck Levere8680a22019-02-11 11:24:48 -0500138 int (*crwrap_req)(struct rpc_task *task,
139 struct xdr_stream *xdr);
Chuck Levera0584ee2019-02-11 11:24:58 -0500140 int (*crunwrap_resp)(struct rpc_task *task,
141 struct xdr_stream *xdr);
Andy Adamson4de6caa2013-08-14 11:59:15 -0400142 int (*crkey_timeout)(struct rpc_cred *);
Jeff Laytona0337d12014-06-21 20:52:16 -0400143 char * (*crstringify_acceptor)(struct rpc_cred *);
Trond Myklebust3021a5bb2018-08-14 13:50:21 -0400144 bool (*crneed_reencode)(struct rpc_task *);
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);
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400151int __init rpcauth_init_module(void);
Stephen Rothwellc135e842010-09-29 14:16:57 +1000152void rpcauth_remove_module(void);
Trond Myklebust5d8d9a42010-07-31 14:29:07 -0400153void rpc_destroy_authunix(void);
Trond Myklebust9499b432007-06-24 15:57:57 -0400154
Trond Myklebustf1c0a862007-06-23 20:17:58 -0400155int rpcauth_register(const struct rpc_authops *);
156int rpcauth_unregister(const struct rpc_authops *);
Sargun Dhillon82b98ca2018-07-05 16:48:50 +0000157struct rpc_auth * rpcauth_create(const struct rpc_auth_create_args *,
Trond Myklebustc2190662013-08-26 19:23:04 -0400158 struct rpc_clnt *);
Trond Myklebustde7a8ce2007-06-23 10:46:47 -0400159void rpcauth_release(struct rpc_auth *);
Chuck Lever9568c5e2013-03-16 15:54:43 -0400160rpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t,
161 struct rpcsec_gss_info *);
Chuck Levera77c8062013-03-16 15:55:10 -0400162int rpcauth_get_gssinfo(rpc_authflavor_t,
163 struct rpcsec_gss_info *);
Chuck Lever6a1a1e32012-07-11 16:31:08 -0400164int rpcauth_list_flavors(rpc_authflavor_t *, int);
Jeff Layton3c6e0bc2016-04-21 20:51:54 -0400165struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t);
Trond Myklebust5fe47552007-06-23 19:55:31 -0400166void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168void put_rpccred(struct rpc_cred *);
Chuck Levere8680a22019-02-11 11:24:48 -0500169int rpcauth_marshcred(struct rpc_task *task,
170 struct xdr_stream *xdr);
Chuck Levera0584ee2019-02-11 11:24:58 -0500171int rpcauth_checkverf(struct rpc_task *task,
172 struct xdr_stream *xdr);
Chuck Levere8680a22019-02-11 11:24:48 -0500173int rpcauth_wrap_req_encode(struct rpc_task *task,
174 struct xdr_stream *xdr);
175int rpcauth_wrap_req(struct rpc_task *task,
176 struct xdr_stream *xdr);
Chuck Levera0584ee2019-02-11 11:24:58 -0500177int rpcauth_unwrap_resp_decode(struct rpc_task *task,
178 struct xdr_stream *xdr);
179int rpcauth_unwrap_resp(struct rpc_task *task,
180 struct xdr_stream *xdr);
Trond Myklebust3021a5bb2018-08-14 13:50:21 -0400181bool rpcauth_xmit_need_reencode(struct rpc_task *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182int rpcauth_refreshcred(struct rpc_task *);
183void rpcauth_invalcred(struct rpc_task *);
184int rpcauth_uptodatecred(struct rpc_task *);
Trond Myklebustf5c21872007-06-25 17:11:20 -0400185int rpcauth_init_credcache(struct rpc_auth *);
Trond Myklebust3ab9bb72007-06-09 15:41:42 -0400186void rpcauth_destroy_credcache(struct rpc_auth *);
187void rpcauth_clear_credcache(struct rpc_cred_cache *);
Jeff Laytona0337d12014-06-21 20:52:16 -0400188char * rpcauth_stringify_acceptor(struct rpc_cred *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190static inline
Trond Myklebust07d02a62018-10-12 13:28:26 -0400191struct rpc_cred *get_rpccred(struct rpc_cred *cred)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Trond Myklebust79b18182018-10-14 10:34:31 -0400193 if (cred != NULL && refcount_inc_not_zero(&cred->cr_count))
Trond Myklebust07d02a62018-10-12 13:28:26 -0400194 return cred;
195 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif /* __KERNEL__ */
199#endif /* _LINUX_SUNRPC_AUTH_H */