blob: 5ac5db4d295f9487ced510634c2b2b65c5f7d20b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02003 * linux/include/linux/sunrpc/gss_api.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Somewhat simplified version of the gss api.
6 *
7 * Dug Song <dugsong@monkey.org>
8 * Andy Adamson <andros@umich.edu>
9 * Bruce Fields <bfields@umich.edu>
10 * Copyright (c) 2000 The Regents of the University of Michigan
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
13#ifndef _LINUX_SUNRPC_GSS_API_H
14#define _LINUX_SUNRPC_GSS_API_H
15
16#ifdef __KERNEL__
17#include <linux/sunrpc/xdr.h>
Chuck Lever6a1a1e32012-07-11 16:31:08 -040018#include <linux/sunrpc/msg_prot.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/uio.h>
20
21/* The mechanism-independent gss-api context: */
22struct gss_ctx {
23 struct gss_api_mech *mech_type;
24 void *internal_ctx_id;
25};
26
27#define GSS_C_NO_BUFFER ((struct xdr_netobj) 0)
28#define GSS_C_NO_CONTEXT ((struct gss_ctx *) 0)
Chuck Lever83523d02013-03-16 15:55:01 -040029#define GSS_C_QOP_DEFAULT (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/*XXX arbitrary length - is this set somewhere? */
32#define GSS_OID_MAX_LEN 32
Chuck Leverfb15b262013-03-16 15:54:34 -040033struct rpcsec_gss_oid {
34 unsigned int len;
35 u8 data[GSS_OID_MAX_LEN];
36};
37
38/* From RFC 3530 */
39struct rpcsec_gss_info {
40 struct rpcsec_gss_oid oid;
41 u32 qop;
42 u32 service;
43};
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* gss-api prototypes; note that these are somewhat simplified versions of
46 * the prototypes specified in RFC 2744. */
47int gss_import_sec_context(
48 const void* input_token,
49 size_t bufsize,
50 struct gss_api_mech *mech,
Trond Myklebust1f4c86c2010-05-13 12:51:02 -040051 struct gss_ctx **ctx_id,
Simo Sorce400f26b2012-05-25 18:09:53 -040052 time_t *endtime,
Trond Myklebust1f4c86c2010-05-13 12:51:02 -040053 gfp_t gfp_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054u32 gss_get_mic(
55 struct gss_ctx *ctx_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 struct xdr_buf *message,
57 struct xdr_netobj *mic_token);
58u32 gss_verify_mic(
59 struct gss_ctx *ctx_id,
60 struct xdr_buf *message,
J. Bruce Fields00fd6e12005-10-13 16:55:18 -040061 struct xdr_netobj *mic_token);
J. Bruce Fields293f1eb2005-10-13 16:54:37 -040062u32 gss_wrap(
63 struct gss_ctx *ctx_id,
J. Bruce Fields293f1eb2005-10-13 16:54:37 -040064 int offset,
65 struct xdr_buf *outbuf,
66 struct page **inpages);
67u32 gss_unwrap(
68 struct gss_ctx *ctx_id,
J. Bruce Fields293f1eb2005-10-13 16:54:37 -040069 int offset,
70 struct xdr_buf *inbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071u32 gss_delete_sec_context(
72 struct gss_ctx **ctx_id);
73
Chuck Lever83523d02013-03-16 15:55:01 -040074rpc_authflavor_t gss_svc_to_pseudoflavor(struct gss_api_mech *, u32 qop,
75 u32 service);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076u32 gss_pseudoflavor_to_service(struct gss_api_mech *, u32 pseudoflavor);
Chuck Lever65b80172016-06-29 13:55:06 -040077bool gss_pseudoflavor_to_datatouch(struct gss_api_mech *, u32 pseudoflavor);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078char *gss_service_to_auth_domain_name(struct gss_api_mech *, u32 service);
79
80struct pf_desc {
81 u32 pseudoflavor;
Chuck Lever83523d02013-03-16 15:55:01 -040082 u32 qop;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 u32 service;
84 char *name;
85 char *auth_domain_name;
Chuck Lever65b80172016-06-29 13:55:06 -040086 bool datatouch;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087};
88
89/* Different mechanisms (e.g., krb5 or spkm3) may implement gss-api, and
90 * mechanisms may be dynamically registered or unregistered by modules. */
91
92/* Each mechanism is described by the following struct: */
93struct gss_api_mech {
94 struct list_head gm_list;
95 struct module *gm_owner;
Chuck Leverfb15b262013-03-16 15:54:34 -040096 struct rpcsec_gss_oid gm_oid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 char *gm_name;
Trond Myklebustf1c0a862007-06-23 20:17:58 -040098 const struct gss_api_ops *gm_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 /* pseudoflavors supported by this mechanism: */
100 int gm_pf_num;
101 struct pf_desc * gm_pfs;
Trond Myklebust683ac662010-04-08 14:09:58 -0400102 /* Should the following be a callback operation instead? */
103 const char *gm_upcall_enctypes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106/* and must provide the following operations: */
107struct gss_api_ops {
108 int (*gss_import_sec_context)(
109 const void *input_token,
110 size_t bufsize,
Trond Myklebust1f4c86c2010-05-13 12:51:02 -0400111 struct gss_ctx *ctx_id,
Simo Sorce400f26b2012-05-25 18:09:53 -0400112 time_t *endtime,
Trond Myklebust1f4c86c2010-05-13 12:51:02 -0400113 gfp_t gfp_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 u32 (*gss_get_mic)(
115 struct gss_ctx *ctx_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 struct xdr_buf *message,
117 struct xdr_netobj *mic_token);
118 u32 (*gss_verify_mic)(
119 struct gss_ctx *ctx_id,
120 struct xdr_buf *message,
J. Bruce Fields00fd6e12005-10-13 16:55:18 -0400121 struct xdr_netobj *mic_token);
J. Bruce Fields293f1eb2005-10-13 16:54:37 -0400122 u32 (*gss_wrap)(
123 struct gss_ctx *ctx_id,
J. Bruce Fields293f1eb2005-10-13 16:54:37 -0400124 int offset,
125 struct xdr_buf *outbuf,
126 struct page **inpages);
127 u32 (*gss_unwrap)(
128 struct gss_ctx *ctx_id,
J. Bruce Fields293f1eb2005-10-13 16:54:37 -0400129 int offset,
130 struct xdr_buf *buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 void (*gss_delete_sec_context)(
132 void *internal_ctx_id);
133};
134
135int gss_mech_register(struct gss_api_mech *);
136void gss_mech_unregister(struct gss_api_mech *);
137
138/* returns a mechanism descriptor given an OID, and increments the mechanism's
139 * reference count. */
J. Bruce Fieldsb1df7632013-04-29 14:03:30 -0400140struct gss_api_mech * gss_mech_get_by_OID(struct rpcsec_gss_oid *);
141
Chuck Lever9568c5e2013-03-16 15:54:43 -0400142/* Given a GSS security tuple, look up a pseudoflavor */
143rpc_authflavor_t gss_mech_info2flavor(struct rpcsec_gss_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Chuck Levera77c8062013-03-16 15:55:10 -0400145/* Given a pseudoflavor, look up a GSS security tuple */
146int gss_mech_flavor2info(rpc_authflavor_t, struct rpcsec_gss_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/* Returns a reference to a mechanism, given a name like "krb5" etc. */
149struct gss_api_mech *gss_mech_get_by_name(const char *);
150
151/* Similar, but get by pseudoflavor. */
152struct gss_api_mech *gss_mech_get_by_pseudoflavor(u32);
153
Bryan Schumaker8f70e952011-03-24 17:12:31 +0000154/* Fill in an array with a list of supported pseudoflavors */
Chuck Lever6a1a1e32012-07-11 16:31:08 -0400155int gss_mech_list_pseudoflavors(rpc_authflavor_t *, int);
Bryan Schumaker8f70e952011-03-24 17:12:31 +0000156
J. Bruce Fields0dc15312013-05-14 16:07:13 -0400157struct gss_api_mech * gss_mech_get(struct gss_api_mech *);
158
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200159/* For every successful gss_mech_get or gss_mech_get_by_* call there must be a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 * corresponding call to gss_mech_put. */
161void gss_mech_put(struct gss_api_mech *);
162
163#endif /* __KERNEL__ */
164#endif /* _LINUX_SUNRPC_GSS_API_H */
165