1
2
3
4
5
6
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#include <linux/cred.h>
19
20struct svc_cred {
21 kuid_t cr_uid;
22 kgid_t cr_gid;
23 struct group_info *cr_group_info;
24 u32 cr_flavor;
25 char *cr_principal;
26};
27
28static inline void free_svc_cred(struct svc_cred *cred)
29{
30 if (cred->cr_group_info)
31 put_group_info(cred->cr_group_info);
32 kfree(cred->cr_principal);
33}
34
35struct svc_rqst;
36struct in6_addr;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57struct auth_domain {
58 struct kref ref;
59 struct hlist_node hash;
60 char *name;
61 struct auth_ops *flavour;
62};
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104struct auth_ops {
105 char * name;
106 struct module *owner;
107 int flavour;
108 int (*accept)(struct svc_rqst *rq, __be32 *authp);
109 int (*release)(struct svc_rqst *rq);
110 void (*domain_release)(struct auth_domain *);
111 int (*set_client)(struct svc_rqst *rq);
112};
113
114#define SVC_GARBAGE 1
115#define SVC_SYSERR 2
116#define SVC_VALID 3
117#define SVC_NEGATIVE 4
118#define SVC_OK 5
119#define SVC_DROP 6
120#define SVC_CLOSE 7
121
122
123
124#define SVC_DENIED 8
125#define SVC_PENDING 9
126#define SVC_COMPLETE 10
127
128struct svc_xprt;
129
130extern int svc_authenticate(struct svc_rqst *rqstp, __be32 *authp);
131extern int svc_authorise(struct svc_rqst *rqstp);
132extern int svc_set_client(struct svc_rqst *rqstp);
133extern int svc_auth_register(rpc_authflavor_t flavor, struct auth_ops *aops);
134extern void svc_auth_unregister(rpc_authflavor_t flavor);
135
136extern struct auth_domain *unix_domain_find(char *name);
137extern void auth_domain_put(struct auth_domain *item);
138extern int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom);
139extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
140extern struct auth_domain *auth_domain_find(char *name);
141extern struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr);
142extern int auth_unix_forget_old(struct auth_domain *dom);
143extern void svcauth_unix_purge(struct net *net);
144extern void svcauth_unix_info_release(struct svc_xprt *xpt);
145extern int svcauth_unix_set_client(struct svc_rqst *rqstp);
146
147extern int unix_gid_cache_create(struct net *net);
148extern void unix_gid_cache_destroy(struct net *net);
149
150static inline unsigned long hash_str(char *name, int bits)
151{
152 unsigned long hash = 0;
153 unsigned long l = 0;
154 int len = 0;
155 unsigned char c;
156 do {
157 if (unlikely(!(c = *name++))) {
158 c = (char)len; len = -1;
159 }
160 l = (l << 8) | c;
161 len++;
162 if ((len & (BITS_PER_LONG/8-1))==0)
163 hash = hash_long(hash^l, BITS_PER_LONG);
164 } while (len);
165 return hash >> (BITS_PER_LONG - bits);
166}
167
168static inline unsigned long hash_mem(char *buf, int length, int bits)
169{
170 unsigned long hash = 0;
171 unsigned long l = 0;
172 int len = 0;
173 unsigned char c;
174 do {
175 if (len == length) {
176 c = (char)len; len = -1;
177 } else
178 c = *buf++;
179 l = (l << 8) | c;
180 len++;
181 if ((len & (BITS_PER_LONG/8-1))==0)
182 hash = hash_long(hash^l, BITS_PER_LONG);
183 } while (len);
184 return hash >> (BITS_PER_LONG - bits);
185}
186
187#endif
188
189#endif
190