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