1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/include/linux/sunrpc/svcauth.h
5 * RPC server-side authentication stuff.
7 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
10 #ifndef _LINUX_SUNRPC_SVCAUTH_H_
11 #define _LINUX_SUNRPC_SVCAUTH_H_
13 #include <linux/string.h>
14 #include <linux/sunrpc/msg_prot.h>
15 #include <linux/sunrpc/cache.h>
16 #include <linux/sunrpc/gss_api.h>
17 #include <linux/sunrpc/clnt.h>
18 #include <linux/hash.h>
19 #include <linux/stringhash.h>
20 #include <linux/cred.h>
25 struct group_info
*cr_group_info
;
26 u32 cr_flavor
; /* pseudoflavor */
27 /* name of form servicetype/hostname@REALM, passed down by
29 char *cr_raw_principal
;
30 /* name of form servicetype@hostname, passed down by
31 * rpc.svcgssd, or computed from the above: */
34 struct gss_api_mech
*cr_gss_mech
;
37 static inline void init_svc_cred(struct svc_cred
*cred
)
39 cred
->cr_group_info
= NULL
;
40 cred
->cr_raw_principal
= NULL
;
41 cred
->cr_principal
= NULL
;
42 cred
->cr_targ_princ
= NULL
;
43 cred
->cr_gss_mech
= NULL
;
46 static inline void free_svc_cred(struct svc_cred
*cred
)
48 if (cred
->cr_group_info
)
49 put_group_info(cred
->cr_group_info
);
50 kfree(cred
->cr_raw_principal
);
51 kfree(cred
->cr_principal
);
52 kfree(cred
->cr_targ_princ
);
53 gss_mech_put(cred
->cr_gss_mech
);
57 struct svc_rqst
; /* forward decl */
60 /* Authentication is done in the context of a domain.
62 * Currently, the nfs server uses the auth_domain to stand
63 * for the "client" listed in /etc/exports.
65 * More generally, a domain might represent a group of clients using
66 * a common mechanism for authentication and having a common mapping
67 * between local identity (uid) and network identity. All clients
68 * in a domain have similar general access rights. Each domain can
69 * contain multiple principals which will have different specific right
70 * based on normal Discretionary Access Control.
72 * A domain is created by an authentication flavour module based on name
73 * only. Userspace then fills in detail on demand.
75 * In the case of auth_unix and auth_null, the auth_domain is also
76 * associated with entries in another cache representing the mapping
77 * of ip addresses to the given client.
81 struct hlist_node hash
;
83 struct auth_ops
*flavour
;
84 struct rcu_head rcu_head
;
87 enum svc_auth_status
{
101 * Each authentication flavour registers an auth_ops
103 * name is simply the name.
104 * flavour gives the auth flavour. It determines where the flavour is registered
105 * accept() is given a request and should verify it.
106 * It should inspect the authenticator and verifier, and possibly the data.
107 * If there is a problem with the authentication *authp should be set.
108 * The return value of accept() can indicate:
109 * OK - authorised. client and credential are set in rqstp.
110 * reqbuf points to arguments
111 * resbuf points to good place for results. verfier
112 * is (probably) already in place. Certainly space is
114 * DROP - simply drop the request. It may have been deferred
115 * CLOSE - like SVC_DROP, but request is definitely lost.
116 * If there is a tcp connection, it should be closed.
117 * GARBAGE - rpc garbage_args error
118 * SYSERR - rpc system_err error
119 * DENIED - authp holds reason for denial.
120 * COMPLETE - the reply is encoded already and ready to be sent; no
121 * further processing is necessary. (This is used for processing
122 * null procedure calls which are used to set up encryption
125 * accept is passed the proc number so that it can accept NULL rpc requests
126 * even if it cannot authenticate the client (as is sometimes appropriate).
128 * release() is given a request after the procedure has been run.
129 * It should sign/encrypt the results if needed
132 * This call releases a domain.
135 * Given a pending request (struct svc_rqst), finds and assigns
136 * an appropriate 'auth_domain' as the client.
139 * Returns RPC_AUTH pseudoflavor in use by @rqstp.
143 struct module
*owner
;
146 enum svc_auth_status (*accept
)(struct svc_rqst
*rqstp
);
147 int (*release
)(struct svc_rqst
*rqstp
);
148 void (*domain_release
)(struct auth_domain
*dom
);
149 enum svc_auth_status (*set_client
)(struct svc_rqst
*rqstp
);
150 rpc_authflavor_t (*pseudoflavor
)(struct svc_rqst
*rqstp
);
155 extern rpc_authflavor_t
svc_auth_flavor(struct svc_rqst
*rqstp
);
156 extern int svc_authorise(struct svc_rqst
*rqstp
);
157 extern enum svc_auth_status
svc_set_client(struct svc_rqst
*rqstp
);
158 extern int svc_auth_register(rpc_authflavor_t flavor
, struct auth_ops
*aops
);
159 extern void svc_auth_unregister(rpc_authflavor_t flavor
);
161 extern void svcauth_map_clnt_to_svc_cred_local(struct rpc_clnt
*clnt
,
165 extern struct auth_domain
*unix_domain_find(char *name
);
166 extern void auth_domain_put(struct auth_domain
*item
);
167 extern struct auth_domain
*auth_domain_lookup(char *name
, struct auth_domain
*new);
168 extern struct auth_domain
*auth_domain_find(char *name
);
169 extern void svcauth_unix_purge(struct net
*net
);
170 extern void svcauth_unix_info_release(struct svc_xprt
*xpt
);
171 extern enum svc_auth_status
svcauth_unix_set_client(struct svc_rqst
*rqstp
);
173 extern int unix_gid_cache_create(struct net
*net
);
174 extern void unix_gid_cache_destroy(struct net
*net
);
177 * The <stringhash.h> functions are good enough that we don't need to
178 * use hash_32() on them; just extracting the high bits is enough.
180 static inline unsigned long hash_str(char const *name
, int bits
)
182 return hashlen_hash(hashlen_string(NULL
, name
)) >> (32 - bits
);
185 static inline unsigned long hash_mem(char const *buf
, int length
, int bits
)
187 return full_name_hash(NULL
, buf
, length
) >> (32 - bits
);
190 #endif /* _LINUX_SUNRPC_SVCAUTH_H_ */