Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * linux/include/linux/sunrpc/auth.h
0004  *
0005  * Declarations for the RPC client authentication machinery.
0006  *
0007  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
0008  */
0009 
0010 #ifndef _LINUX_SUNRPC_AUTH_H
0011 #define _LINUX_SUNRPC_AUTH_H
0012 
0013 #include <linux/sunrpc/sched.h>
0014 #include <linux/sunrpc/msg_prot.h>
0015 #include <linux/sunrpc/xdr.h>
0016 
0017 #include <linux/atomic.h>
0018 #include <linux/rcupdate.h>
0019 #include <linux/uidgid.h>
0020 #include <linux/utsname.h>
0021 
0022 /*
0023  * Maximum size of AUTH_NONE authentication information, in XDR words.
0024  */
0025 #define NUL_CALLSLACK   (4)
0026 #define NUL_REPLYSLACK  (2)
0027 
0028 /*
0029  * Size of the nodename buffer. RFC1831 specifies a hard limit of 255 bytes,
0030  * but Linux hostnames are actually limited to __NEW_UTS_LEN bytes.
0031  */
0032 #define UNX_MAXNODENAME __NEW_UTS_LEN
0033 #define UNX_CALLSLACK   (21 + XDR_QUADLEN(UNX_MAXNODENAME))
0034 #define UNX_NGROUPS 16
0035 
0036 struct rpcsec_gss_info;
0037 
0038 struct auth_cred {
0039     const struct cred *cred;
0040     const char *principal;  /* If present, this is a machine credential */
0041 };
0042 
0043 /*
0044  * Client user credentials
0045  */
0046 struct rpc_auth;
0047 struct rpc_credops;
0048 struct rpc_cred {
0049     struct hlist_node   cr_hash;    /* hash chain */
0050     struct list_head    cr_lru;     /* lru garbage collection */
0051     struct rcu_head     cr_rcu;
0052     struct rpc_auth *   cr_auth;
0053     const struct rpc_credops *cr_ops;
0054     unsigned long       cr_expire;  /* when to gc */
0055     unsigned long       cr_flags;   /* various flags */
0056     refcount_t      cr_count;   /* ref count */
0057     const struct cred   *cr_cred;
0058 
0059     /* per-flavor data */
0060 };
0061 #define RPCAUTH_CRED_NEW    0
0062 #define RPCAUTH_CRED_UPTODATE   1
0063 #define RPCAUTH_CRED_HASHED 2
0064 #define RPCAUTH_CRED_NEGATIVE   3
0065 
0066 const struct cred *rpc_machine_cred(void);
0067 
0068 /*
0069  * Client authentication handle
0070  */
0071 struct rpc_cred_cache;
0072 struct rpc_authops;
0073 struct rpc_auth {
0074     unsigned int        au_cslack;  /* call cred size estimate */
0075     unsigned int        au_rslack;  /* reply cred size estimate */
0076     unsigned int        au_verfsize;    /* size of reply verifier */
0077     unsigned int        au_ralign;  /* words before UL header */
0078 
0079     unsigned long       au_flags;
0080     const struct rpc_authops *au_ops;
0081     rpc_authflavor_t    au_flavor;  /* pseudoflavor (note may
0082                          * differ from the flavor in
0083                          * au_ops->au_flavor in gss
0084                          * case) */
0085     refcount_t      au_count;   /* Reference counter */
0086 
0087     struct rpc_cred_cache * au_credcache;
0088     /* per-flavor data */
0089 };
0090 
0091 /* rpc_auth au_flags */
0092 #define RPCAUTH_AUTH_DATATOUCH      (1)
0093 #define RPCAUTH_AUTH_UPDATE_SLACK   (2)
0094 
0095 struct rpc_auth_create_args {
0096     rpc_authflavor_t pseudoflavor;
0097     const char *target_name;
0098 };
0099 
0100 /* Flags for rpcauth_lookupcred() */
0101 #define RPCAUTH_LOOKUP_NEW      0x01    /* Accept an uninitialised cred */
0102 #define RPCAUTH_LOOKUP_ASYNC        0x02    /* Don't block waiting for memory */
0103 
0104 /*
0105  * Client authentication ops
0106  */
0107 struct rpc_authops {
0108     struct module       *owner;
0109     rpc_authflavor_t    au_flavor;  /* flavor (RPC_AUTH_*) */
0110     char *          au_name;
0111     struct rpc_auth *   (*create)(const struct rpc_auth_create_args *,
0112                       struct rpc_clnt *);
0113     void            (*destroy)(struct rpc_auth *);
0114 
0115     int         (*hash_cred)(struct auth_cred *, unsigned int);
0116     struct rpc_cred *   (*lookup_cred)(struct rpc_auth *, struct auth_cred *, int);
0117     struct rpc_cred *   (*crcreate)(struct rpc_auth*, struct auth_cred *, int, gfp_t);
0118     rpc_authflavor_t    (*info2flavor)(struct rpcsec_gss_info *);
0119     int         (*flavor2info)(rpc_authflavor_t,
0120                         struct rpcsec_gss_info *);
0121     int         (*key_timeout)(struct rpc_auth *,
0122                         struct rpc_cred *);
0123 };
0124 
0125 struct rpc_credops {
0126     const char *        cr_name;    /* Name of the auth flavour */
0127     int         (*cr_init)(struct rpc_auth *, struct rpc_cred *);
0128     void            (*crdestroy)(struct rpc_cred *);
0129 
0130     int         (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
0131     int         (*crmarshal)(struct rpc_task *task,
0132                          struct xdr_stream *xdr);
0133     int         (*crrefresh)(struct rpc_task *);
0134     int         (*crvalidate)(struct rpc_task *task,
0135                           struct xdr_stream *xdr);
0136     int         (*crwrap_req)(struct rpc_task *task,
0137                           struct xdr_stream *xdr);
0138     int         (*crunwrap_resp)(struct rpc_task *task,
0139                          struct xdr_stream *xdr);
0140     int         (*crkey_timeout)(struct rpc_cred *);
0141     char *          (*crstringify_acceptor)(struct rpc_cred *);
0142     bool            (*crneed_reencode)(struct rpc_task *);
0143 };
0144 
0145 extern const struct rpc_authops authunix_ops;
0146 extern const struct rpc_authops authnull_ops;
0147 
0148 int __init      rpc_init_authunix(void);
0149 int __init      rpcauth_init_module(void);
0150 void            rpcauth_remove_module(void);
0151 void            rpc_destroy_authunix(void);
0152 
0153 int         rpcauth_register(const struct rpc_authops *);
0154 int         rpcauth_unregister(const struct rpc_authops *);
0155 struct rpc_auth *   rpcauth_create(const struct rpc_auth_create_args *,
0156                 struct rpc_clnt *);
0157 void            rpcauth_release(struct rpc_auth *);
0158 rpc_authflavor_t    rpcauth_get_pseudoflavor(rpc_authflavor_t,
0159                 struct rpcsec_gss_info *);
0160 int         rpcauth_get_gssinfo(rpc_authflavor_t,
0161                 struct rpcsec_gss_info *);
0162 struct rpc_cred *   rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int, gfp_t);
0163 void            rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
0164 struct rpc_cred *   rpcauth_lookupcred(struct rpc_auth *, int);
0165 void            put_rpccred(struct rpc_cred *);
0166 int         rpcauth_marshcred(struct rpc_task *task,
0167                       struct xdr_stream *xdr);
0168 int         rpcauth_checkverf(struct rpc_task *task,
0169                       struct xdr_stream *xdr);
0170 int         rpcauth_wrap_req_encode(struct rpc_task *task,
0171                         struct xdr_stream *xdr);
0172 int         rpcauth_wrap_req(struct rpc_task *task,
0173                      struct xdr_stream *xdr);
0174 int         rpcauth_unwrap_resp_decode(struct rpc_task *task,
0175                            struct xdr_stream *xdr);
0176 int         rpcauth_unwrap_resp(struct rpc_task *task,
0177                         struct xdr_stream *xdr);
0178 bool            rpcauth_xmit_need_reencode(struct rpc_task *task);
0179 int         rpcauth_refreshcred(struct rpc_task *);
0180 void            rpcauth_invalcred(struct rpc_task *);
0181 int         rpcauth_uptodatecred(struct rpc_task *);
0182 int         rpcauth_init_credcache(struct rpc_auth *);
0183 void            rpcauth_destroy_credcache(struct rpc_auth *);
0184 void            rpcauth_clear_credcache(struct rpc_cred_cache *);
0185 char *          rpcauth_stringify_acceptor(struct rpc_cred *);
0186 
0187 static inline
0188 struct rpc_cred *get_rpccred(struct rpc_cred *cred)
0189 {
0190     if (cred != NULL && refcount_inc_not_zero(&cred->cr_count))
0191         return cred;
0192     return NULL;
0193 }
0194 
0195 #endif /* _LINUX_SUNRPC_AUTH_H */