1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * linux/include/linux/sunrpc/svcauth.h 4 * 5 * RPC server-side authentication stuff. 6 * 7 * Copyright (C) 1995, 1996 Olaf Kirch <[email protected]> 8 */ 9 10 #ifndef _LINUX_SUNRPC_SVCAUTH_H_ 11 #define _LINUX_SUNRPC_SVCAUTH_H_ 12 13 #ifdef __KERNEL__ 14 15 #include <linux/string.h> 16 #include <linux/sunrpc/msg_prot.h> 17 #include <linux/sunrpc/cache.h> 18 #include <linux/sunrpc/gss_api.h> 19 #include <linux/hash.h> 20 #include <linux/stringhash.h> 21 #include <linux/cred.h> 22 23 struct svc_cred { 24 kuid_t cr_uid; 25 kgid_t cr_gid; 26 struct group_info *cr_group_info; 27 u32 cr_flavor; /* pseudoflavor */ 28 /* name of form servicetype/hostname@REALM, passed down by 29 * gss-proxy: */ 30 char *cr_raw_principal; 31 /* name of form servicetype@hostname, passed down by 32 * rpc.svcgssd, or computed from the above: */ 33 char *cr_principal; 34 struct gss_api_mech *cr_gss_mech; 35 }; 36 37 static inline void init_svc_cred(struct svc_cred *cred) 38 { 39 cred->cr_group_info = NULL; 40 cred->cr_raw_principal = NULL; 41 cred->cr_principal = NULL; 42 cred->cr_gss_mech = NULL; 43 } 44 45 static inline void free_svc_cred(struct svc_cred *cred) 46 { 47 if (cred->cr_group_info) 48 put_group_info(cred->cr_group_info); 49 kfree(cred->cr_raw_principal); 50 kfree(cred->cr_principal); 51 gss_mech_put(cred->cr_gss_mech); 52 init_svc_cred(cred); 53 } 54 55 struct svc_rqst; /* forward decl */ 56 struct in6_addr; 57 58 /* Authentication is done in the context of a domain. 59 * 60 * Currently, the nfs server uses the auth_domain to stand 61 * for the "client" listed in /etc/exports. 62 * 63 * More generally, a domain might represent a group of clients using 64 * a common mechanism for authentication and having a common mapping 65 * between local identity (uid) and network identity. All clients 66 * in a domain have similar general access rights. Each domain can 67 * contain multiple principals which will have different specific right 68 * based on normal Discretionary Access Control. 69 * 70 * A domain is created by an authentication flavour module based on name 71 * only. Userspace then fills in detail on demand. 72 * 73 * In the case of auth_unix and auth_null, the auth_domain is also 74 * associated with entries in another cache representing the mapping 75 * of ip addresses to the given client. 76 */ 77 struct auth_domain { 78 struct kref ref; 79 struct hlist_node hash; 80 char *name; 81 struct auth_ops *flavour; 82 }; 83 84 /* 85 * Each authentication flavour registers an auth_ops 86 * structure. 87 * name is simply the name. 88 * flavour gives the auth flavour. It determines where the flavour is registered 89 * accept() is given a request and should verify it. 90 * It should inspect the authenticator and verifier, and possibly the data. 91 * If there is a problem with the authentication *authp should be set. 92 * The return value of accept() can indicate: 93 * OK - authorised. client and credential are set in rqstp. 94 * reqbuf points to arguments 95 * resbuf points to good place for results. verfier 96 * is (probably) already in place. Certainly space is 97 * reserved for it. 98 * DROP - simply drop the request. It may have been deferred 99 * GARBAGE - rpc garbage_args error 100 * SYSERR - rpc system_err error 101 * DENIED - authp holds reason for denial. 102 * COMPLETE - the reply is encoded already and ready to be sent; no 103 * further processing is necessary. (This is used for processing 104 * null procedure calls which are used to set up encryption 105 * contexts.) 106 * 107 * accept is passed the proc number so that it can accept NULL rpc requests 108 * even if it cannot authenticate the client (as is sometimes appropriate). 109 * 110 * release() is given a request after the procedure has been run. 111 * It should sign/encrypt the results if needed 112 * It should return: 113 * OK - the resbuf is ready to be sent 114 * DROP - the reply should be quitely dropped 115 * DENIED - authp holds a reason for MSG_DENIED 116 * SYSERR - rpc system_err 117 * 118 * domain_release() 119 * This call releases a domain. 120 * set_client() 121 * Givens a pending request (struct svc_rqst), finds and assigns 122 * an appropriate 'auth_domain' as the client. 123 */ 124 struct auth_ops { 125 char * name; 126 struct module *owner; 127 int flavour; 128 int (*accept)(struct svc_rqst *rq, __be32 *authp); 129 int (*release)(struct svc_rqst *rq); 130 void (*domain_release)(struct auth_domain *); 131 int (*set_client)(struct svc_rqst *rq); 132 }; 133 134 #define SVC_GARBAGE 1 135 #define SVC_SYSERR 2 136 #define SVC_VALID 3 137 #define SVC_NEGATIVE 4 138 #define SVC_OK 5 139 #define SVC_DROP 6 140 #define SVC_CLOSE 7 /* Like SVC_DROP, but request is definitely 141 * lost so if there is a tcp connection, it 142 * should be closed 143 */ 144 #define SVC_DENIED 8 145 #define SVC_PENDING 9 146 #define SVC_COMPLETE 10 147 148 struct svc_xprt; 149 150 extern int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp); 151 extern int svc_authorise(struct svc_rqst *rqstp); 152 extern int svc_set_client(struct svc_rqst *rqstp); 153 extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops); 154 extern void svc_auth_unregister(rpc_authflavor_t flavor); 155 156 extern struct auth_domain *unix_domain_find(char *name); 157 extern void auth_domain_put(struct auth_domain *item); 158 extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom); 159 extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new); 160 extern struct auth_domain *auth_domain_find(char *name); 161 extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr); 162 extern int auth_unix_forget_old(struct auth_domain *dom); 163 extern void svcauth_unix_purge(struct net *net); 164 extern void svcauth_unix_info_release(struct svc_xprt *xpt); 165 extern int svcauth_unix_set_client(struct svc_rqst *rqstp); 166 167 extern int unix_gid_cache_create(struct net *net); 168 extern void unix_gid_cache_destroy(struct net *net); 169 170 /* 171 * The <stringhash.h> functions are good enough that we don't need to 172 * use hash_32() on them; just extracting the high bits is enough. 173 */ 174 static inline unsigned long hash_str(char const *name, int bits) 175 { 176 return hashlen_hash(hashlen_string(NULL, name)) >> (32 - bits); 177 } 178 179 static inline unsigned long hash_mem(char const *buf, int length, int bits) 180 { 181 return full_name_hash(NULL, buf, length) >> (32 - bits); 182 } 183 184 #endif /* __KERNEL__ */ 185 186 #endif /* _LINUX_SUNRPC_SVCAUTH_H_ */ 187