blob: 2c54683b91decae417967b5a0703c96d84de9714 [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>
17#include <linux/hash.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019struct svc_cred {
20 uid_t cr_uid;
21 gid_t cr_gid;
22 struct group_info *cr_group_info;
23};
24
25struct svc_rqst; /* forward decl */
Aurélien Charbonf15364b2008-01-18 15:50:56 +010026struct in6_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* Authentication is done in the context of a domain.
29 *
30 * Currently, the nfs server uses the auth_domain to stand
31 * for the "client" listed in /etc/exports.
32 *
33 * More generally, a domain might represent a group of clients using
34 * a common mechanism for authentication and having a common mapping
35 * between local identity (uid) and network identity. All clients
36 * in a domain have similar general access rights. Each domain can
37 * contain multiple principals which will have different specific right
38 * based on normal Discretionary Access Control.
39 *
40 * A domain is created by an authentication flavour module based on name
41 * only. Userspace then fills in detail on demand.
42 *
43 * In the case of auth_unix and auth_null, the auth_domain is also
44 * associated with entries in another cache representing the mapping
45 * of ip addresses to the given client.
46 */
47struct auth_domain {
NeilBrownefc36aa2006-03-27 01:14:59 -080048 struct kref ref;
49 struct hlist_node hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 char *name;
NeilBrownefc36aa2006-03-27 01:14:59 -080051 struct auth_ops *flavour;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54/*
55 * Each authentication flavour registers an auth_ops
56 * structure.
57 * name is simply the name.
58 * flavour gives the auth flavour. It determines where the flavour is registered
59 * accept() is given a request and should verify it.
60 * It should inspect the authenticator and verifier, and possibly the data.
61 * If there is a problem with the authentication *authp should be set.
62 * The return value of accept() can indicate:
63 * OK - authorised. client and credential are set in rqstp.
64 * reqbuf points to arguments
65 * resbuf points to good place for results. verfier
66 * is (probably) already in place. Certainly space is
67 * reserved for it.
68 * DROP - simply drop the request. It may have been deferred
69 * GARBAGE - rpc garbage_args error
70 * SYSERR - rpc system_err error
71 * DENIED - authp holds reason for denial.
72 * COMPLETE - the reply is encoded already and ready to be sent; no
73 * further processing is necessary. (This is used for processing
74 * null procedure calls which are used to set up encryption
75 * contexts.)
76 *
77 * accept is passed the proc number so that it can accept NULL rpc requests
78 * even if it cannot authenticate the client (as is sometimes appropriate).
79 *
80 * release() is given a request after the procedure has been run.
81 * It should sign/encrypt the results if needed
82 * It should return:
83 * OK - the resbuf is ready to be sent
84 * DROP - the reply should be quitely dropped
85 * DENIED - authp holds a reason for MSG_DENIED
86 * SYSERR - rpc system_err
87 *
88 * domain_release()
89 * This call releases a domain.
NeilBrownefc36aa2006-03-27 01:14:59 -080090 * set_client()
91 * Givens a pending request (struct svc_rqst), finds and assigns
92 * an appropriate 'auth_domain' as the client.
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 */
94struct auth_ops {
95 char * name;
96 struct module *owner;
97 int flavour;
Alexey Dobriyand8ed0292006-09-26 22:29:38 -070098 int (*accept)(struct svc_rqst *rq, __be32 *authp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 int (*release)(struct svc_rqst *rq);
100 void (*domain_release)(struct auth_domain *);
101 int (*set_client)(struct svc_rqst *rq);
102};
103
104#define SVC_GARBAGE 1
105#define SVC_SYSERR 2
106#define SVC_VALID 3
107#define SVC_NEGATIVE 4
108#define SVC_OK 5
109#define SVC_DROP 6
NeilBrown1ebede82010-08-12 17:04:07 +1000110#define SVC_CLOSE 7 /* Like SVC_DROP, but request is definitely
111 * lost so if there is a tcp connection, it
112 * should be closed
113 */
114#define SVC_DENIED 8
115#define SVC_PENDING 9
116#define SVC_COMPLETE 10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Pavel Emelyanove3bfca02010-09-27 13:58:42 +0400118struct svc_xprt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Alexey Dobriyand8ed0292006-09-26 22:29:38 -0700120extern int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121extern int svc_authorise(struct svc_rqst *rqstp);
122extern int svc_set_client(struct svc_rqst *rqstp);
123extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
124extern void svc_auth_unregister(rpc_authflavor_t flavor);
125
126extern struct auth_domain *unix_domain_find(char *name);
127extern void auth_domain_put(struct auth_domain *item);
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400128extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom);
NeilBrownefc36aa2006-03-27 01:14:59 -0800129extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130extern struct auth_domain *auth_domain_find(char *name);
Pavel Emelyanov352114f2010-09-27 13:59:48 +0400131extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132extern int auth_unix_forget_old(struct auth_domain *dom);
Stanislav Kinsburskye5f06f72012-04-11 15:13:28 +0400133extern void svcauth_unix_purge(struct net *net);
Pavel Emelyanove3bfca02010-09-27 13:58:42 +0400134extern void svcauth_unix_info_release(struct svc_xprt *xpt);
J. Bruce Fields3ab4d8b2007-07-17 04:04:46 -0700135extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Trond Myklebust09acfea2012-03-11 15:22:54 -0400137extern int unix_gid_cache_create(struct net *net);
138extern void unix_gid_cache_destroy(struct net *net);
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140static inline unsigned long hash_str(char *name, int bits)
141{
142 unsigned long hash = 0;
143 unsigned long l = 0;
144 int len = 0;
145 unsigned char c;
146 do {
147 if (unlikely(!(c = *name++))) {
148 c = (char)len; len = -1;
149 }
150 l = (l << 8) | c;
151 len++;
152 if ((len & (BITS_PER_LONG/8-1))==0)
153 hash = hash_long(hash^l, BITS_PER_LONG);
154 } while (len);
155 return hash >> (BITS_PER_LONG - bits);
156}
157
158static inline unsigned long hash_mem(char *buf, int length, int bits)
159{
160 unsigned long hash = 0;
161 unsigned long l = 0;
162 int len = 0;
163 unsigned char c;
164 do {
165 if (len == length) {
166 c = (char)len; len = -1;
167 } else
168 c = *buf++;
169 l = (l << 8) | c;
170 len++;
171 if ((len & (BITS_PER_LONG/8-1))==0)
172 hash = hash_long(hash^l, BITS_PER_LONG);
173 } while (len);
174 return hash >> (BITS_PER_LONG - bits);
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#endif /* __KERNEL__ */
178
179#endif /* _LINUX_SUNRPC_SVCAUTH_H_ */