blob: d03932055328ccef696dd3008dcddc2d5d1c5d70 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/include/linux/sunrpc/svcauth.h
3 *
4 * RPC server-side authentication stuff.
5 *
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 */
8
9#ifndef _LINUX_SUNRPC_SVCAUTH_H_
10#define _LINUX_SUNRPC_SVCAUTH_H_
11
12#ifdef __KERNEL__
13
14#include <linux/string.h>
15#include <linux/sunrpc/msg_prot.h>
16#include <linux/sunrpc/cache.h>
J. Bruce Fields0dc15312013-05-14 16:07:13 -040017#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/hash.h>
George Spelvin917ea162016-05-20 13:31:33 -040019#include <linux/stringhash.h>
J. Bruce Fields03a4e1f2012-05-14 19:55:22 -040020#include <linux/cred.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022struct svc_cred {
Eric W. Biederman7eaf0402013-02-01 16:31:17 -080023 kuid_t cr_uid;
24 kgid_t cr_gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 struct group_info *cr_group_info;
J. Bruce Fieldsd5497fc2012-05-14 22:06:49 -040026 u32 cr_flavor; /* pseudoflavor */
J. Bruce Fields414ca012015-11-20 10:48:02 -050027 /* name of form servicetype/hostname@REALM, passed down by
28 * gss-proxy: */
29 char *cr_raw_principal;
30 /* name of form servicetype@hostname, passed down by
31 * rpc.svcgssd, or computed from the above: */
32 char *cr_principal;
J. Bruce Fields0dc15312013-05-14 16:07:13 -040033 struct gss_api_mech *cr_gss_mech;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034};
35
J. Bruce Fields44234062013-05-14 16:53:40 -040036static inline void init_svc_cred(struct svc_cred *cred)
37{
38 cred->cr_group_info = NULL;
J. Bruce Fields414ca012015-11-20 10:48:02 -050039 cred->cr_raw_principal = NULL;
J. Bruce Fields44234062013-05-14 16:53:40 -040040 cred->cr_principal = NULL;
41 cred->cr_gss_mech = NULL;
42}
43
J. Bruce Fields03a4e1f2012-05-14 19:55:22 -040044static inline void free_svc_cred(struct svc_cred *cred)
45{
46 if (cred->cr_group_info)
47 put_group_info(cred->cr_group_info);
J. Bruce Fields414ca012015-11-20 10:48:02 -050048 kfree(cred->cr_raw_principal);
J. Bruce Fields03a4e1f2012-05-14 19:55:22 -040049 kfree(cred->cr_principal);
J. Bruce Fields0dc15312013-05-14 16:07:13 -040050 gss_mech_put(cred->cr_gss_mech);
51 init_svc_cred(cred);
J. Bruce Fields03a4e1f2012-05-14 19:55:22 -040052}
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054struct svc_rqst; /* forward decl */
Aurélien Charbonf15364b2008-01-18 15:50:56 +010055struct in6_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57/* Authentication is done in the context of a domain.
58 *
59 * Currently, the nfs server uses the auth_domain to stand
60 * for the "client" listed in /etc/exports.
61 *
62 * More generally, a domain might represent a group of clients using
63 * a common mechanism for authentication and having a common mapping
64 * between local identity (uid) and network identity. All clients
65 * in a domain have similar general access rights. Each domain can
66 * contain multiple principals which will have different specific right
67 * based on normal Discretionary Access Control.
68 *
69 * A domain is created by an authentication flavour module based on name
70 * only. Userspace then fills in detail on demand.
71 *
72 * In the case of auth_unix and auth_null, the auth_domain is also
73 * associated with entries in another cache representing the mapping
74 * of ip addresses to the given client.
75 */
76struct auth_domain {
NeilBrownefc36aa2006-03-27 01:14:59 -080077 struct kref ref;
78 struct hlist_node hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 char *name;
NeilBrownefc36aa2006-03-27 01:14:59 -080080 struct auth_ops *flavour;
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
83/*
84 * Each authentication flavour registers an auth_ops
85 * structure.
86 * name is simply the name.
87 * flavour gives the auth flavour. It determines where the flavour is registered
88 * accept() is given a request and should verify it.
89 * It should inspect the authenticator and verifier, and possibly the data.
90 * If there is a problem with the authentication *authp should be set.
91 * The return value of accept() can indicate:
92 * OK - authorised. client and credential are set in rqstp.
93 * reqbuf points to arguments
94 * resbuf points to good place for results. verfier
95 * is (probably) already in place. Certainly space is
96 * reserved for it.
97 * DROP - simply drop the request. It may have been deferred
98 * GARBAGE - rpc garbage_args error
99 * SYSERR - rpc system_err error
100 * DENIED - authp holds reason for denial.
101 * COMPLETE - the reply is encoded already and ready to be sent; no
102 * further processing is necessary. (This is used for processing
103 * null procedure calls which are used to set up encryption
104 * contexts.)
105 *
106 * accept is passed the proc number so that it can accept NULL rpc requests
107 * even if it cannot authenticate the client (as is sometimes appropriate).
108 *
109 * release() is given a request after the procedure has been run.
110 * It should sign/encrypt the results if needed
111 * It should return:
112 * OK - the resbuf is ready to be sent
113 * DROP - the reply should be quitely dropped
114 * DENIED - authp holds a reason for MSG_DENIED
115 * SYSERR - rpc system_err
116 *
117 * domain_release()
118 * This call releases a domain.
NeilBrownefc36aa2006-03-27 01:14:59 -0800119 * set_client()
120 * Givens a pending request (struct svc_rqst), finds and assigns
121 * an appropriate 'auth_domain' as the client.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 */
123struct auth_ops {
124 char * name;
125 struct module *owner;
126 int flavour;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700127 int (*accept)(struct svc_rqst *rq, __be32 *authp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 int (*release)(struct svc_rqst *rq);
129 void (*domain_release)(struct auth_domain *);
130 int (*set_client)(struct svc_rqst *rq);
131};
132
133#define SVC_GARBAGE 1
134#define SVC_SYSERR 2
135#define SVC_VALID 3
136#define SVC_NEGATIVE 4
137#define SVC_OK 5
138#define SVC_DROP 6
NeilBrown1ebede82010-08-12 17:04:07 +1000139#define SVC_CLOSE 7 /* Like SVC_DROP, but request is definitely
140 * lost so if there is a tcp connection, it
141 * should be closed
142 */
143#define SVC_DENIED 8
144#define SVC_PENDING 9
145#define SVC_COMPLETE 10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Pavel Emelyanove3bfca02010-09-27 13:58:42 +0400147struct svc_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700149extern int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150extern int svc_authorise(struct svc_rqst *rqstp);
151extern int svc_set_client(struct svc_rqst *rqstp);
152extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
153extern void svc_auth_unregister(rpc_authflavor_t flavor);
154
155extern struct auth_domain *unix_domain_find(char *name);
156extern void auth_domain_put(struct auth_domain *item);
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400157extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom);
NeilBrownefc36aa2006-03-27 01:14:59 -0800158extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159extern struct auth_domain *auth_domain_find(char *name);
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400160extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161extern int auth_unix_forget_old(struct auth_domain *dom);
Stanislav Kinsburskye5f06f72012-04-11 15:13:28 +0400162extern void svcauth_unix_purge(struct net *net);
Pavel Emelyanove3bfca02010-09-27 13:58:42 +0400163extern void svcauth_unix_info_release(struct svc_xprt *xpt);
J. Bruce Fields3ab4d8b2007-07-17 04:04:46 -0700164extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Trond Myklebust09acfea2012-03-11 15:22:54 -0400166extern int unix_gid_cache_create(struct net *net);
167extern void unix_gid_cache_destroy(struct net *net);
168
George Spelvin917ea162016-05-20 13:31:33 -0400169/*
170 * The <stringhash.h> functions are good enough that we don't need to
171 * use hash_32() on them; just extracting the high bits is enough.
172 */
173static inline unsigned long hash_str(char const *name, int bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Linus Torvalds8387ff22016-06-10 07:51:30 -0700175 return hashlen_hash(hashlen_string(NULL, name)) >> (32 - bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
George Spelvin917ea162016-05-20 13:31:33 -0400178static inline unsigned long hash_mem(char const *buf, int length, int bits)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Linus Torvalds8387ff22016-06-10 07:51:30 -0700180 return full_name_hash(NULL, buf, length) >> (32 - bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#endif /* __KERNEL__ */
184
185#endif /* _LINUX_SUNRPC_SVCAUTH_H_ */