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