syscons,vt: improve phrasing in kern.vty man page description
[freebsd-src.git] / sys / rpc / rpcsec_gss.h
blob7466d60776003aca9fef92b885ba712506510d13
1 /*-
2 * Copyright (c) 2008 Doug Rabson
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD$
29 #ifndef _RPCSEC_GSS_H
30 #define _RPCSEC_GSS_H
32 #include <kgssapi/gssapi.h>
34 #ifndef MAX_GSS_MECH
35 #define MAX_GSS_MECH 64
36 #endif
39 * Define the types of security service required for rpc_gss_seccreate().
41 typedef enum {
42 rpc_gss_svc_default = 0,
43 rpc_gss_svc_none = 1,
44 rpc_gss_svc_integrity = 2,
45 rpc_gss_svc_privacy = 3
46 } rpc_gss_service_t;
49 * Structure containing options for rpc_gss_seccreate().
51 typedef struct {
52 int req_flags; /* GSS request bits */
53 int time_req; /* requested credential lifetime */
54 gss_cred_id_t my_cred; /* GSS credential */
55 gss_channel_bindings_t input_channel_bindings;
56 } rpc_gss_options_req_t;
59 * Structure containing options returned by rpc_gss_seccreate().
61 typedef struct {
62 int major_status;
63 int minor_status;
64 u_int rpcsec_version;
65 int ret_flags;
66 int time_req;
67 gss_ctx_id_t gss_context;
68 char actual_mechanism[MAX_GSS_MECH];
69 } rpc_gss_options_ret_t;
72 * Client principal type. Used as an argument to
73 * rpc_gss_get_principal_name(). Also referenced by the
74 * rpc_gss_rawcred_t structure.
76 typedef struct {
77 int len;
78 char name[1];
79 } *rpc_gss_principal_t;
82 * Structure for raw credentials used by rpc_gss_getcred() and
83 * rpc_gss_set_callback().
85 typedef struct {
86 u_int version; /* RPC version number */
87 const char *mechanism; /* security mechanism */
88 const char *qop; /* quality of protection */
89 rpc_gss_principal_t client_principal; /* client name */
90 const char *svc_principal; /* server name */
91 rpc_gss_service_t service; /* service type */
92 } rpc_gss_rawcred_t;
95 * Unix credentials derived from raw credentials. Returned by
96 * rpc_gss_getcred().
98 typedef struct {
99 uid_t uid; /* user ID */
100 gid_t gid; /* group ID */
101 short gidlen;
102 gid_t *gidlist; /* list of groups */
103 } rpc_gss_ucred_t;
106 * Structure used to enforce a particular QOP and service.
108 typedef struct {
109 bool_t locked;
110 rpc_gss_rawcred_t *raw_cred;
111 } rpc_gss_lock_t;
114 * Callback structure used by rpc_gss_set_callback().
116 typedef struct {
117 u_int program; /* RPC program number */
118 u_int version; /* RPC version number */
119 /* user defined callback */
120 bool_t (*callback)(struct svc_req *req,
121 gss_cred_id_t deleg,
122 gss_ctx_id_t gss_context,
123 rpc_gss_lock_t *lock,
124 void **cookie);
125 } rpc_gss_callback_t;
128 * Structure used to return error information by rpc_gss_get_error()
130 typedef struct {
131 int rpc_gss_error;
132 int system_error; /* same as errno */
133 } rpc_gss_error_t;
136 * Values for rpc_gss_error
138 #define RPC_GSS_ER_SUCCESS 0 /* no error */
139 #define RPC_GSS_ER_SYSTEMERROR 1 /* system error */
141 __BEGIN_DECLS
143 #ifdef _KERNEL
145 * Set up a structure of entry points for the kgssapi module and inline
146 * functions named rpc_gss_XXX_call() to use them, so that the kgssapi
147 * module doesn't need to be loaded for the NFS modules to work using
148 * AUTH_SYS. The kgssapi modules will be loaded by the gssd(8) daemon
149 * when it is started up and the entry points will then be filled in.
151 typedef AUTH *rpc_gss_secfind_ftype(CLIENT *clnt, struct ucred *cred,
152 const char *principal, gss_OID mech_oid,
153 rpc_gss_service_t service);
154 typedef void rpc_gss_secpurge_ftype(CLIENT *clnt);
155 typedef AUTH *rpc_gss_seccreate_ftype(CLIENT *clnt, struct ucred *cred,
156 const char *clnt_principal, const char *principal,
157 const char *mechanism, rpc_gss_service_t service,
158 const char *qop, rpc_gss_options_req_t *options_req,
159 rpc_gss_options_ret_t *options_ret);
160 typedef bool_t rpc_gss_set_defaults_ftype(AUTH *auth,
161 rpc_gss_service_t service, const char *qop);
162 typedef int rpc_gss_max_data_length_ftype(AUTH *handle,
163 int max_tp_unit_len);
164 typedef void rpc_gss_get_error_ftype(rpc_gss_error_t *error);
165 typedef bool_t rpc_gss_mech_to_oid_ftype(const char *mech, gss_OID *oid_ret);
166 typedef bool_t rpc_gss_oid_to_mech_ftype(gss_OID oid, const char **mech_ret);
167 typedef bool_t rpc_gss_qop_to_num_ftype(const char *qop, const char *mech,
168 u_int *num_ret);
169 typedef const char **rpc_gss_get_mechanisms_ftype(void);
170 typedef bool_t rpc_gss_get_versions_ftype(u_int *vers_hi, u_int *vers_lo);
171 typedef bool_t rpc_gss_is_installed_ftype(const char *mech);
172 typedef bool_t rpc_gss_set_svc_name_ftype(const char *principal,
173 const char *mechanism, u_int req_time, u_int program,
174 u_int version);
175 typedef void rpc_gss_clear_svc_name_ftype(u_int program, u_int version);
176 typedef bool_t rpc_gss_getcred_ftype(struct svc_req *req,
177 rpc_gss_rawcred_t **rcred,
178 rpc_gss_ucred_t **ucred, void **cookie);
179 typedef bool_t rpc_gss_set_callback_ftype(rpc_gss_callback_t *cb);
180 typedef void rpc_gss_clear_callback_ftype(rpc_gss_callback_t *cb);
181 typedef bool_t rpc_gss_get_principal_name_ftype(rpc_gss_principal_t *principal,
182 const char *mech, const char *name, const char *node,
183 const char *domain);
184 typedef int rpc_gss_svc_max_data_length_ftype(struct svc_req *req,
185 int max_tp_unit_len);
186 typedef void rpc_gss_refresh_auth_ftype(AUTH *auth);
188 struct rpc_gss_entries {
189 rpc_gss_secfind_ftype *rpc_gss_secfind;
190 rpc_gss_secpurge_ftype *rpc_gss_secpurge;
191 rpc_gss_seccreate_ftype *rpc_gss_seccreate;
192 rpc_gss_set_defaults_ftype *rpc_gss_set_defaults;
193 rpc_gss_max_data_length_ftype *rpc_gss_max_data_length;
194 rpc_gss_get_error_ftype *rpc_gss_get_error;
195 rpc_gss_mech_to_oid_ftype *rpc_gss_mech_to_oid;
196 rpc_gss_oid_to_mech_ftype *rpc_gss_oid_to_mech;
197 rpc_gss_qop_to_num_ftype *rpc_gss_qop_to_num;
198 rpc_gss_get_mechanisms_ftype *rpc_gss_get_mechanisms;
199 rpc_gss_get_versions_ftype *rpc_gss_get_versions;
200 rpc_gss_is_installed_ftype *rpc_gss_is_installed;
201 rpc_gss_set_svc_name_ftype *rpc_gss_set_svc_name;
202 rpc_gss_clear_svc_name_ftype *rpc_gss_clear_svc_name;
203 rpc_gss_getcred_ftype *rpc_gss_getcred;
204 rpc_gss_set_callback_ftype *rpc_gss_set_callback;
205 rpc_gss_clear_callback_ftype *rpc_gss_clear_callback;
206 rpc_gss_get_principal_name_ftype *rpc_gss_get_principal_name;
207 rpc_gss_svc_max_data_length_ftype *rpc_gss_svc_max_data_length;
208 rpc_gss_refresh_auth_ftype *rpc_gss_refresh_auth;
210 extern struct rpc_gss_entries rpc_gss_entries;
212 /* Functions to access the entry points. */
213 static __inline AUTH *
214 rpc_gss_secfind_call(CLIENT *clnt, struct ucred *cred, const char *principal,
215 gss_OID mech_oid, rpc_gss_service_t service)
217 AUTH *ret = NULL;
219 if (rpc_gss_entries.rpc_gss_secfind != NULL)
220 ret = (*rpc_gss_entries.rpc_gss_secfind)(clnt, cred, principal,
221 mech_oid, service);
222 return (ret);
225 static __inline void
226 rpc_gss_secpurge_call(CLIENT *clnt)
229 if (rpc_gss_entries.rpc_gss_secpurge != NULL)
230 (*rpc_gss_entries.rpc_gss_secpurge)(clnt);
233 static __inline AUTH *
234 rpc_gss_seccreate_call(CLIENT *clnt, struct ucred *cred,
235 const char *clnt_principal, const char *principal, const char *mechanism,
236 rpc_gss_service_t service, const char *qop,
237 rpc_gss_options_req_t *options_req, rpc_gss_options_ret_t *options_ret)
239 AUTH *ret = NULL;
241 if (rpc_gss_entries.rpc_gss_seccreate != NULL)
242 ret = (*rpc_gss_entries.rpc_gss_seccreate)(clnt, cred,
243 clnt_principal, principal, mechanism, service, qop,
244 options_req, options_ret);
245 return (ret);
248 static __inline bool_t
249 rpc_gss_set_defaults_call(AUTH *auth, rpc_gss_service_t service,
250 const char *qop)
252 bool_t ret = 1;
254 if (rpc_gss_entries.rpc_gss_set_defaults != NULL)
255 ret = (*rpc_gss_entries.rpc_gss_set_defaults)(auth, service,
256 qop);
257 return (ret);
260 static __inline int
261 rpc_gss_max_data_length_call(AUTH *handle, int max_tp_unit_len)
263 int ret = 0;
265 if (rpc_gss_entries.rpc_gss_max_data_length != NULL)
266 ret = (*rpc_gss_entries.rpc_gss_max_data_length)(handle,
267 max_tp_unit_len);
268 return (ret);
271 static __inline void
272 rpc_gss_get_error_call(rpc_gss_error_t *error)
275 if (rpc_gss_entries.rpc_gss_get_error != NULL)
276 (*rpc_gss_entries.rpc_gss_get_error)(error);
279 static __inline bool_t
280 rpc_gss_mech_to_oid_call(const char *mech, gss_OID *oid_ret)
282 bool_t ret = 1;
284 if (rpc_gss_entries.rpc_gss_mech_to_oid != NULL)
285 ret = (*rpc_gss_entries.rpc_gss_mech_to_oid)(mech, oid_ret);
286 return (ret);
289 static __inline bool_t
290 rpc_gss_oid_to_mech_call(gss_OID oid, const char **mech_ret)
292 bool_t ret = 1;
294 if (rpc_gss_entries.rpc_gss_oid_to_mech != NULL)
295 ret = (*rpc_gss_entries.rpc_gss_oid_to_mech)(oid, mech_ret);
296 return (ret);
299 static __inline bool_t
300 rpc_gss_qop_to_num_call(const char *qop, const char *mech, u_int *num_ret)
302 bool_t ret = 1;
304 if (rpc_gss_entries.rpc_gss_qop_to_num != NULL)
305 ret = (*rpc_gss_entries.rpc_gss_qop_to_num)(qop, mech, num_ret);
306 return (ret);
309 static __inline const char **
310 rpc_gss_get_mechanisms_call(void)
312 const char **ret = NULL;
314 if (rpc_gss_entries.rpc_gss_get_mechanisms != NULL)
315 ret = (*rpc_gss_entries.rpc_gss_get_mechanisms)();
316 return (ret);
319 static __inline bool_t
320 rpc_gss_get_versions_call(u_int *vers_hi, u_int *vers_lo)
322 bool_t ret = 1;
324 if (rpc_gss_entries.rpc_gss_get_versions != NULL)
325 ret = (*rpc_gss_entries.rpc_gss_get_versions)(vers_hi, vers_lo);
326 return (ret);
329 static __inline bool_t
330 rpc_gss_is_installed_call(const char *mech)
332 bool_t ret = 1;
334 if (rpc_gss_entries.rpc_gss_is_installed != NULL)
335 ret = (*rpc_gss_entries.rpc_gss_is_installed)(mech);
336 return (ret);
339 static __inline bool_t
340 rpc_gss_set_svc_name_call(const char *principal, const char *mechanism,
341 u_int req_time, u_int program, u_int version)
343 bool_t ret = 1;
345 if (rpc_gss_entries.rpc_gss_set_svc_name != NULL)
346 ret = (*rpc_gss_entries.rpc_gss_set_svc_name)(principal,
347 mechanism, req_time, program, version);
348 return (ret);
351 static __inline void
352 rpc_gss_clear_svc_name_call(u_int program, u_int version)
355 if (rpc_gss_entries.rpc_gss_clear_svc_name != NULL)
356 (*rpc_gss_entries.rpc_gss_clear_svc_name)(program, version);
359 static __inline bool_t
360 rpc_gss_getcred_call(struct svc_req *req, rpc_gss_rawcred_t **rcred,
361 rpc_gss_ucred_t **ucred, void **cookie)
363 bool_t ret = 1;
365 if (rpc_gss_entries.rpc_gss_getcred != NULL)
366 ret = (*rpc_gss_entries.rpc_gss_getcred)(req, rcred, ucred,
367 cookie);
368 return (ret);
371 static __inline bool_t
372 rpc_gss_set_callback_call(rpc_gss_callback_t *cb)
374 bool_t ret = 1;
376 if (rpc_gss_entries.rpc_gss_set_callback != NULL)
377 ret = (*rpc_gss_entries.rpc_gss_set_callback)(cb);
378 return (ret);
381 static __inline void
382 rpc_gss_clear_callback_call(rpc_gss_callback_t *cb)
385 if (rpc_gss_entries.rpc_gss_clear_callback != NULL)
386 (*rpc_gss_entries.rpc_gss_clear_callback)(cb);
389 static __inline bool_t
390 rpc_gss_get_principal_name_call(rpc_gss_principal_t *principal,
391 const char *mech, const char *name, const char *node, const char *domain)
393 bool_t ret = 1;
395 if (rpc_gss_entries.rpc_gss_get_principal_name != NULL)
396 ret = (*rpc_gss_entries.rpc_gss_get_principal_name)(principal,
397 mech, name, node, domain);
398 return (ret);
401 static __inline int
402 rpc_gss_svc_max_data_length_call(struct svc_req *req, int max_tp_unit_len)
404 int ret = 0;
406 if (rpc_gss_entries.rpc_gss_svc_max_data_length != NULL)
407 ret = (*rpc_gss_entries.rpc_gss_svc_max_data_length)(req,
408 max_tp_unit_len);
409 return (ret);
412 static __inline void
413 rpc_gss_refresh_auth_call(AUTH *auth)
416 if (rpc_gss_entries.rpc_gss_refresh_auth != NULL)
417 (*rpc_gss_entries.rpc_gss_refresh_auth)(auth);
420 AUTH *rpc_gss_secfind(CLIENT *clnt, struct ucred *cred,
421 const char *principal, gss_OID mech_oid, rpc_gss_service_t service);
422 void rpc_gss_secpurge(CLIENT *clnt);
423 void rpc_gss_refresh_auth(AUTH *auth);
424 AUTH *rpc_gss_seccreate(CLIENT *clnt, struct ucred *cred,
425 const char *clnt_principal, const char *principal,
426 const char *mechanism, rpc_gss_service_t service,
427 const char *qop, rpc_gss_options_req_t *options_req,
428 rpc_gss_options_ret_t *options_ret);
429 #else /* !_KERNEL */
430 AUTH *rpc_gss_seccreate(CLIENT *clnt, struct ucred *cred,
431 const char *principal, const char *mechanism, rpc_gss_service_t service,
432 const char *qop, rpc_gss_options_req_t *options_req,
433 rpc_gss_options_ret_t *options_ret);
434 #endif /* _KERNEL */
435 bool_t rpc_gss_set_defaults(AUTH *auth, rpc_gss_service_t service,
436 const char *qop);
437 int rpc_gss_max_data_length(AUTH *handle, int max_tp_unit_len);
438 void rpc_gss_get_error(rpc_gss_error_t *error);
440 bool_t rpc_gss_mech_to_oid(const char *mech, gss_OID *oid_ret);
441 bool_t rpc_gss_oid_to_mech(gss_OID oid, const char **mech_ret);
442 bool_t rpc_gss_qop_to_num(const char *qop, const char *mech, u_int *num_ret);
443 const char **rpc_gss_get_mechanisms(void);
444 const char **rpc_gss_get_mech_info(const char *mech, rpc_gss_service_t *service);
445 bool_t rpc_gss_get_versions(u_int *vers_hi, u_int *vers_lo);
446 bool_t rpc_gss_is_installed(const char *mech);
448 bool_t rpc_gss_set_svc_name(const char *principal, const char *mechanism,
449 u_int req_time, u_int program, u_int version);
450 void rpc_gss_clear_svc_name(u_int program, u_int version);
451 bool_t rpc_gss_getcred(struct svc_req *req, rpc_gss_rawcred_t **rcred,
452 rpc_gss_ucred_t **ucred, void **cookie);
453 bool_t rpc_gss_set_callback(rpc_gss_callback_t *cb);
454 void rpc_gss_clear_callback(rpc_gss_callback_t *cb);
455 bool_t rpc_gss_get_principal_name(rpc_gss_principal_t *principal,
456 const char *mech, const char *name, const char *node, const char *domain);
457 int rpc_gss_svc_max_data_length(struct svc_req *req, int max_tp_unit_len);
460 * Internal interface from the RPC implementation.
462 #ifndef _KERNEL
463 bool_t __rpc_gss_wrap(AUTH *auth, void *header, size_t headerlen,
464 XDR* xdrs, xdrproc_t xdr_args, void *args_ptr);
465 bool_t __rpc_gss_unwrap(AUTH *auth, XDR* xdrs, xdrproc_t xdr_args,
466 void *args_ptr);
467 #endif
468 bool_t __rpc_gss_set_error(int rpc_gss_error, int system_error);
470 __END_DECLS
472 #endif /* !_RPCSEC_GSS_H */