18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * linux/include/linux/sunrpc/auth.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Declarations for the RPC client authentication machinery. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _LINUX_SUNRPC_AUTH_H 118c2ecf20Sopenharmony_ci#define _LINUX_SUNRPC_AUTH_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/sunrpc/sched.h> 148c2ecf20Sopenharmony_ci#include <linux/sunrpc/msg_prot.h> 158c2ecf20Sopenharmony_ci#include <linux/sunrpc/xdr.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/atomic.h> 188c2ecf20Sopenharmony_ci#include <linux/rcupdate.h> 198c2ecf20Sopenharmony_ci#include <linux/uidgid.h> 208c2ecf20Sopenharmony_ci#include <linux/utsname.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci/* 238c2ecf20Sopenharmony_ci * Maximum size of AUTH_NONE authentication information, in XDR words. 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci#define NUL_CALLSLACK (4) 268c2ecf20Sopenharmony_ci#define NUL_REPLYSLACK (2) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * Size of the nodename buffer. RFC1831 specifies a hard limit of 255 bytes, 308c2ecf20Sopenharmony_ci * but Linux hostnames are actually limited to __NEW_UTS_LEN bytes. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci#define UNX_MAXNODENAME __NEW_UTS_LEN 338c2ecf20Sopenharmony_ci#define UNX_CALLSLACK (21 + XDR_QUADLEN(UNX_MAXNODENAME)) 348c2ecf20Sopenharmony_ci#define UNX_NGROUPS 16 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct rpcsec_gss_info; 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct auth_cred { 398c2ecf20Sopenharmony_ci const struct cred *cred; 408c2ecf20Sopenharmony_ci const char *principal; /* If present, this is a machine credential */ 418c2ecf20Sopenharmony_ci}; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci/* 448c2ecf20Sopenharmony_ci * Client user credentials 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_cistruct rpc_auth; 478c2ecf20Sopenharmony_cistruct rpc_credops; 488c2ecf20Sopenharmony_cistruct rpc_cred { 498c2ecf20Sopenharmony_ci struct hlist_node cr_hash; /* hash chain */ 508c2ecf20Sopenharmony_ci struct list_head cr_lru; /* lru garbage collection */ 518c2ecf20Sopenharmony_ci struct rcu_head cr_rcu; 528c2ecf20Sopenharmony_ci struct rpc_auth * cr_auth; 538c2ecf20Sopenharmony_ci const struct rpc_credops *cr_ops; 548c2ecf20Sopenharmony_ci unsigned long cr_expire; /* when to gc */ 558c2ecf20Sopenharmony_ci unsigned long cr_flags; /* various flags */ 568c2ecf20Sopenharmony_ci refcount_t cr_count; /* ref count */ 578c2ecf20Sopenharmony_ci const struct cred *cr_cred; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci /* per-flavor data */ 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci#define RPCAUTH_CRED_NEW 0 628c2ecf20Sopenharmony_ci#define RPCAUTH_CRED_UPTODATE 1 638c2ecf20Sopenharmony_ci#define RPCAUTH_CRED_HASHED 2 648c2ecf20Sopenharmony_ci#define RPCAUTH_CRED_NEGATIVE 3 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciconst struct cred *rpc_machine_cred(void); 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci/* 698c2ecf20Sopenharmony_ci * Client authentication handle 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_cistruct rpc_cred_cache; 728c2ecf20Sopenharmony_cistruct rpc_authops; 738c2ecf20Sopenharmony_cistruct rpc_auth { 748c2ecf20Sopenharmony_ci unsigned int au_cslack; /* call cred size estimate */ 758c2ecf20Sopenharmony_ci unsigned int au_rslack; /* reply cred size estimate */ 768c2ecf20Sopenharmony_ci unsigned int au_verfsize; /* size of reply verifier */ 778c2ecf20Sopenharmony_ci unsigned int au_ralign; /* words before UL header */ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci unsigned long au_flags; 808c2ecf20Sopenharmony_ci const struct rpc_authops *au_ops; 818c2ecf20Sopenharmony_ci rpc_authflavor_t au_flavor; /* pseudoflavor (note may 828c2ecf20Sopenharmony_ci * differ from the flavor in 838c2ecf20Sopenharmony_ci * au_ops->au_flavor in gss 848c2ecf20Sopenharmony_ci * case) */ 858c2ecf20Sopenharmony_ci refcount_t au_count; /* Reference counter */ 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci struct rpc_cred_cache * au_credcache; 888c2ecf20Sopenharmony_ci /* per-flavor data */ 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/* rpc_auth au_flags */ 928c2ecf20Sopenharmony_ci#define RPCAUTH_AUTH_DATATOUCH (1) 938c2ecf20Sopenharmony_ci#define RPCAUTH_AUTH_UPDATE_SLACK (2) 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistruct rpc_auth_create_args { 968c2ecf20Sopenharmony_ci rpc_authflavor_t pseudoflavor; 978c2ecf20Sopenharmony_ci const char *target_name; 988c2ecf20Sopenharmony_ci}; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* Flags for rpcauth_lookupcred() */ 1018c2ecf20Sopenharmony_ci#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* 1048c2ecf20Sopenharmony_ci * Client authentication ops 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_cistruct rpc_authops { 1078c2ecf20Sopenharmony_ci struct module *owner; 1088c2ecf20Sopenharmony_ci rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */ 1098c2ecf20Sopenharmony_ci char * au_name; 1108c2ecf20Sopenharmony_ci struct rpc_auth * (*create)(const struct rpc_auth_create_args *, 1118c2ecf20Sopenharmony_ci struct rpc_clnt *); 1128c2ecf20Sopenharmony_ci void (*destroy)(struct rpc_auth *); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci int (*hash_cred)(struct auth_cred *, unsigned int); 1158c2ecf20Sopenharmony_ci struct rpc_cred * (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int); 1168c2ecf20Sopenharmony_ci struct rpc_cred * (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t); 1178c2ecf20Sopenharmony_ci rpc_authflavor_t (*info2flavor)(struct rpcsec_gss_info *); 1188c2ecf20Sopenharmony_ci int (*flavor2info)(rpc_authflavor_t, 1198c2ecf20Sopenharmony_ci struct rpcsec_gss_info *); 1208c2ecf20Sopenharmony_ci int (*key_timeout)(struct rpc_auth *, 1218c2ecf20Sopenharmony_ci struct rpc_cred *); 1228c2ecf20Sopenharmony_ci}; 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_cistruct rpc_credops { 1258c2ecf20Sopenharmony_ci const char * cr_name; /* Name of the auth flavour */ 1268c2ecf20Sopenharmony_ci int (*cr_init)(struct rpc_auth *, struct rpc_cred *); 1278c2ecf20Sopenharmony_ci void (*crdestroy)(struct rpc_cred *); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci int (*crmatch)(struct auth_cred *, struct rpc_cred *, int); 1308c2ecf20Sopenharmony_ci int (*crmarshal)(struct rpc_task *task, 1318c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1328c2ecf20Sopenharmony_ci int (*crrefresh)(struct rpc_task *); 1338c2ecf20Sopenharmony_ci int (*crvalidate)(struct rpc_task *task, 1348c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1358c2ecf20Sopenharmony_ci int (*crwrap_req)(struct rpc_task *task, 1368c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1378c2ecf20Sopenharmony_ci int (*crunwrap_resp)(struct rpc_task *task, 1388c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1398c2ecf20Sopenharmony_ci int (*crkey_timeout)(struct rpc_cred *); 1408c2ecf20Sopenharmony_ci char * (*crstringify_acceptor)(struct rpc_cred *); 1418c2ecf20Sopenharmony_ci bool (*crneed_reencode)(struct rpc_task *); 1428c2ecf20Sopenharmony_ci}; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ciextern const struct rpc_authops authunix_ops; 1458c2ecf20Sopenharmony_ciextern const struct rpc_authops authnull_ops; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ciint __init rpc_init_authunix(void); 1488c2ecf20Sopenharmony_ciint __init rpcauth_init_module(void); 1498c2ecf20Sopenharmony_civoid rpcauth_remove_module(void); 1508c2ecf20Sopenharmony_civoid rpc_destroy_authunix(void); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ciint rpcauth_register(const struct rpc_authops *); 1538c2ecf20Sopenharmony_ciint rpcauth_unregister(const struct rpc_authops *); 1548c2ecf20Sopenharmony_cistruct rpc_auth * rpcauth_create(const struct rpc_auth_create_args *, 1558c2ecf20Sopenharmony_ci struct rpc_clnt *); 1568c2ecf20Sopenharmony_civoid rpcauth_release(struct rpc_auth *); 1578c2ecf20Sopenharmony_cirpc_authflavor_t rpcauth_get_pseudoflavor(rpc_authflavor_t, 1588c2ecf20Sopenharmony_ci struct rpcsec_gss_info *); 1598c2ecf20Sopenharmony_ciint rpcauth_get_gssinfo(rpc_authflavor_t, 1608c2ecf20Sopenharmony_ci struct rpcsec_gss_info *); 1618c2ecf20Sopenharmony_cistruct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t); 1628c2ecf20Sopenharmony_civoid rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *); 1638c2ecf20Sopenharmony_cistruct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int); 1648c2ecf20Sopenharmony_civoid put_rpccred(struct rpc_cred *); 1658c2ecf20Sopenharmony_ciint rpcauth_marshcred(struct rpc_task *task, 1668c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1678c2ecf20Sopenharmony_ciint rpcauth_checkverf(struct rpc_task *task, 1688c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1698c2ecf20Sopenharmony_ciint rpcauth_wrap_req_encode(struct rpc_task *task, 1708c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1718c2ecf20Sopenharmony_ciint rpcauth_wrap_req(struct rpc_task *task, 1728c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1738c2ecf20Sopenharmony_ciint rpcauth_unwrap_resp_decode(struct rpc_task *task, 1748c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1758c2ecf20Sopenharmony_ciint rpcauth_unwrap_resp(struct rpc_task *task, 1768c2ecf20Sopenharmony_ci struct xdr_stream *xdr); 1778c2ecf20Sopenharmony_cibool rpcauth_xmit_need_reencode(struct rpc_task *task); 1788c2ecf20Sopenharmony_ciint rpcauth_refreshcred(struct rpc_task *); 1798c2ecf20Sopenharmony_civoid rpcauth_invalcred(struct rpc_task *); 1808c2ecf20Sopenharmony_ciint rpcauth_uptodatecred(struct rpc_task *); 1818c2ecf20Sopenharmony_ciint rpcauth_init_credcache(struct rpc_auth *); 1828c2ecf20Sopenharmony_civoid rpcauth_destroy_credcache(struct rpc_auth *); 1838c2ecf20Sopenharmony_civoid rpcauth_clear_credcache(struct rpc_cred_cache *); 1848c2ecf20Sopenharmony_cichar * rpcauth_stringify_acceptor(struct rpc_cred *); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cistatic inline 1878c2ecf20Sopenharmony_cistruct rpc_cred *get_rpccred(struct rpc_cred *cred) 1888c2ecf20Sopenharmony_ci{ 1898c2ecf20Sopenharmony_ci if (cred != NULL && refcount_inc_not_zero(&cred->cr_count)) 1908c2ecf20Sopenharmony_ci return cred; 1918c2ecf20Sopenharmony_ci return NULL; 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci#endif /* _LINUX_SUNRPC_AUTH_H */ 195