Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * linux/include/linux/sunrpc/svcauth.h
0004  *
0005  * RPC server-side authentication stuff.
0006  *
0007  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
0008  */
0009 
0010 #ifndef _LINUX_SUNRPC_SVCAUTH_H_
0011 #define _LINUX_SUNRPC_SVCAUTH_H_
0012 
0013 #include <linux/string.h>
0014 #include <linux/sunrpc/msg_prot.h>
0015 #include <linux/sunrpc/cache.h>
0016 #include <linux/sunrpc/gss_api.h>
0017 #include <linux/hash.h>
0018 #include <linux/stringhash.h>
0019 #include <linux/cred.h>
0020 
0021 struct svc_cred {
0022     kuid_t          cr_uid;
0023     kgid_t          cr_gid;
0024     struct group_info   *cr_group_info;
0025     u32         cr_flavor; /* pseudoflavor */
0026     /* name of form servicetype/hostname@REALM, passed down by
0027      * gss-proxy: */
0028     char            *cr_raw_principal;
0029     /* name of form servicetype@hostname, passed down by
0030      * rpc.svcgssd, or computed from the above: */
0031     char            *cr_principal;
0032     char            *cr_targ_princ;
0033     struct gss_api_mech *cr_gss_mech;
0034 };
0035 
0036 static inline void init_svc_cred(struct svc_cred *cred)
0037 {
0038     cred->cr_group_info = NULL;
0039     cred->cr_raw_principal = NULL;
0040     cred->cr_principal = NULL;
0041     cred->cr_targ_princ = NULL;
0042     cred->cr_gss_mech = NULL;
0043 }
0044 
0045 static inline void free_svc_cred(struct svc_cred *cred)
0046 {
0047     if (cred->cr_group_info)
0048         put_group_info(cred->cr_group_info);
0049     kfree(cred->cr_raw_principal);
0050     kfree(cred->cr_principal);
0051     kfree(cred->cr_targ_princ);
0052     gss_mech_put(cred->cr_gss_mech);
0053     init_svc_cred(cred);
0054 }
0055 
0056 struct svc_rqst;        /* forward decl */
0057 struct in6_addr;
0058 
0059 /* Authentication is done in the context of a domain.
0060  *
0061  * Currently, the nfs server uses the auth_domain to stand
0062  * for the "client" listed in /etc/exports.
0063  *
0064  * More generally, a domain might represent a group of clients using
0065  * a common mechanism for authentication and having a common mapping
0066  * between local identity (uid) and network identity.  All clients
0067  * in a domain have similar general access rights.  Each domain can
0068  * contain multiple principals which will have different specific right
0069  * based on normal Discretionary Access Control.
0070  *
0071  * A domain is created by an authentication flavour module based on name
0072  * only.  Userspace then fills in detail on demand.
0073  *
0074  * In the case of auth_unix and auth_null, the auth_domain is also
0075  * associated with entries in another cache representing the mapping
0076  * of ip addresses to the given client.
0077  */
0078 struct auth_domain {
0079     struct kref     ref;
0080     struct hlist_node   hash;
0081     char            *name;
0082     struct auth_ops     *flavour;
0083     struct rcu_head     rcu_head;
0084 };
0085 
0086 /*
0087  * Each authentication flavour registers an auth_ops
0088  * structure.
0089  * name is simply the name.
0090  * flavour gives the auth flavour. It determines where the flavour is registered
0091  * accept() is given a request and should verify it.
0092  *   It should inspect the authenticator and verifier, and possibly the data.
0093  *    If there is a problem with the authentication *authp should be set.
0094  *    The return value of accept() can indicate:
0095  *      OK - authorised. client and credential are set in rqstp.
0096  *           reqbuf points to arguments
0097  *           resbuf points to good place for results.  verfier
0098  *             is (probably) already in place.  Certainly space is
0099  *         reserved for it.
0100  *      DROP - simply drop the request. It may have been deferred
0101  *      GARBAGE - rpc garbage_args error
0102  *      SYSERR - rpc system_err error
0103  *      DENIED - authp holds reason for denial.
0104  *      COMPLETE - the reply is encoded already and ready to be sent; no
0105  *      further processing is necessary.  (This is used for processing
0106  *      null procedure calls which are used to set up encryption
0107  *      contexts.)
0108  *
0109  *   accept is passed the proc number so that it can accept NULL rpc requests
0110  *   even if it cannot authenticate the client (as is sometimes appropriate).
0111  *
0112  * release() is given a request after the procedure has been run.
0113  *  It should sign/encrypt the results if needed
0114  * It should return:
0115  *    OK - the resbuf is ready to be sent
0116  *    DROP - the reply should be quitely dropped
0117  *    DENIED - authp holds a reason for MSG_DENIED
0118  *    SYSERR - rpc system_err
0119  *
0120  * domain_release()
0121  *   This call releases a domain.
0122  * set_client()
0123  *   Givens a pending request (struct svc_rqst), finds and assigns
0124  *   an appropriate 'auth_domain' as the client.
0125  */
0126 struct auth_ops {
0127     char *  name;
0128     struct module *owner;
0129     int flavour;
0130     int (*accept)(struct svc_rqst *rq);
0131     int (*release)(struct svc_rqst *rq);
0132     void    (*domain_release)(struct auth_domain *);
0133     int (*set_client)(struct svc_rqst *rq);
0134 };
0135 
0136 #define SVC_GARBAGE 1
0137 #define SVC_SYSERR  2
0138 #define SVC_VALID   3
0139 #define SVC_NEGATIVE    4
0140 #define SVC_OK      5
0141 #define SVC_DROP    6
0142 #define SVC_CLOSE   7   /* Like SVC_DROP, but request is definitely
0143                  * lost so if there is a tcp connection, it
0144                  * should be closed
0145                  */
0146 #define SVC_DENIED  8
0147 #define SVC_PENDING 9
0148 #define SVC_COMPLETE    10
0149 
0150 struct svc_xprt;
0151 
0152 extern int  svc_authenticate(struct svc_rqst *rqstp);
0153 extern int  svc_authorise(struct svc_rqst *rqstp);
0154 extern int  svc_set_client(struct svc_rqst *rqstp);
0155 extern int  svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
0156 extern void svc_auth_unregister(rpc_authflavor_t flavor);
0157 
0158 extern struct auth_domain *unix_domain_find(char *name);
0159 extern void auth_domain_put(struct auth_domain *item);
0160 extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom);
0161 extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
0162 extern struct auth_domain *auth_domain_find(char *name);
0163 extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
0164 extern int auth_unix_forget_old(struct auth_domain *dom);
0165 extern void svcauth_unix_purge(struct net *net);
0166 extern void svcauth_unix_info_release(struct svc_xprt *xpt);
0167 extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
0168 
0169 extern int unix_gid_cache_create(struct net *net);
0170 extern void unix_gid_cache_destroy(struct net *net);
0171 
0172 /*
0173  * The <stringhash.h> functions are good enough that we don't need to
0174  * use hash_32() on them; just extracting the high bits is enough.
0175  */
0176 static inline unsigned long hash_str(char const *name, int bits)
0177 {
0178     return hashlen_hash(hashlen_string(NULL, name)) >> (32 - bits);
0179 }
0180 
0181 static inline unsigned long hash_mem(char const *buf, int length, int bits)
0182 {
0183     return full_name_hash(NULL, buf, length) >> (32 - bits);
0184 }
0185 
0186 #endif /* _LINUX_SUNRPC_SVCAUTH_H_ */