ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / sunrpc / gss_api.h
1 /*
2  * linux/include/linux/gss_api.h
3  *
4  * Somewhat simplified version of the gss api.
5  *
6  * Dug Song <dugsong@monkey.org>
7  * Andy Adamson <andros@umich.edu>
8  * Bruce Fields <bfields@umich.edu>
9  * Copyright (c) 2000 The Regents of the University of Michigan
10  *
11  * $Id$
12  */
13
14 #ifndef _LINUX_SUNRPC_GSS_API_H
15 #define _LINUX_SUNRPC_GSS_API_H
16
17 #ifdef __KERNEL__
18 #include <linux/sunrpc/xdr.h>
19 #include <linux/uio.h>
20
21 /* The mechanism-independent gss-api context: */
22 struct 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)
29 #define GSS_C_NULL_OID          ((struct xdr_netobj) 0)
30
31 /*XXX  arbitrary length - is this set somewhere? */
32 #define GSS_OID_MAX_LEN 32
33
34 /* gss-api prototypes; note that these are somewhat simplified versions of
35  * the prototypes specified in RFC 2744. */
36 u32 gss_import_sec_context(
37                 struct xdr_netobj       *input_token,
38                 struct gss_api_mech     *mech,
39                 struct gss_ctx          **ctx_id);
40 u32 gss_get_mic(
41                 struct gss_ctx          *ctx_id,
42                 u32                     qop,
43                 struct xdr_buf          *message,
44                 struct xdr_netobj       *mic_token);
45 u32 gss_verify_mic(
46                 struct gss_ctx          *ctx_id,
47                 struct xdr_buf          *message,
48                 struct xdr_netobj       *mic_token,
49                 u32                     *qstate);
50 u32 gss_delete_sec_context(
51                 struct gss_ctx          **ctx_id);
52
53 /* We maintain a list of the pseudoflavors (equivalently, mechanism-qop-service
54  * triples) that we currently support: */
55
56 struct sup_sec_triple {
57         struct list_head        triples;
58         u32                     pseudoflavor;
59         struct gss_api_mech     *mech;
60         u32                     qop;
61         u32                     service;
62 };
63
64 int gss_register_triple(u32 pseudoflavor, struct gss_api_mech *mech, u32 qop,
65                         u32 service);
66 int gss_unregister_triple(u32 pseudoflavor);
67 int gss_pseudoflavor_supported(u32 pseudoflavor);
68 u32 gss_cmp_triples(u32 oid_len, char *oid_data, u32 qop, u32 service);
69 u32 gss_get_pseudoflavor(struct gss_ctx *ctx_id, u32 qop, u32 service);
70 u32 gss_pseudoflavor_to_service(u32 pseudoflavor);
71 /* Both return NULL on failure: */
72 struct gss_api_mech * gss_pseudoflavor_to_mech(u32 pseudoflavor);
73 int gss_pseudoflavor_to_mechOID(u32 pseudoflavor, struct xdr_netobj *mech);
74
75 /* Different mechanisms (e.g., krb5 or spkm3) may implement gss-api, and
76  * mechanisms may be dynamically registered or unregistered by modules.
77  * Our only built-in mechanism is a trivial debugging mechanism that provides
78  * no actual security; the following function registers that mechanism: */
79
80 void gss_mech_register_debug(void);
81
82 /* Each mechanism is described by the following struct: */
83 struct gss_api_mech {
84         struct xdr_netobj       gm_oid;
85         struct list_head        gm_list;
86         atomic_t                gm_count;
87         struct gss_api_ops      *gm_ops;
88 };
89
90 /* and must provide the following operations: */
91 struct gss_api_ops {
92         char *name;
93         u32 (*gss_import_sec_context)(
94                         struct xdr_netobj       *input_token,
95                         struct gss_ctx          *ctx_id);
96         u32 (*gss_get_mic)(
97                         struct gss_ctx          *ctx_id,
98                         u32                     qop, 
99                         struct xdr_buf          *message,
100                         struct xdr_netobj       *mic_token);
101         u32 (*gss_verify_mic)(
102                         struct gss_ctx          *ctx_id,
103                         struct xdr_buf          *message,
104                         struct xdr_netobj       *mic_token,
105                         u32                     *qstate);
106         void (*gss_delete_sec_context)(
107                         void                    *internal_ctx_id);
108 };
109
110 /* Returns nonzero on failure. */
111 int gss_mech_register(struct xdr_netobj *, struct gss_api_ops *);
112
113 /* Returns nonzero iff someone still has a reference to this mech. */
114 int gss_mech_unregister(struct gss_api_mech *);
115
116 /* Returns nonzer iff someone still has a reference to some mech. */
117 int gss_mech_unregister_all(void);
118
119 /* returns a mechanism descriptor given an OID, an increments the mechanism's
120  * reference count. */
121 struct gss_api_mech * gss_mech_get_by_OID(struct xdr_netobj *);
122
123 /* Similar, but get by name like "krb5", "spkm", etc., instead of OID. */
124 struct gss_api_mech *gss_mech_get_by_name(char *);
125
126 /* Just increments the mechanism's reference count and returns its input: */
127 struct gss_api_mech * gss_mech_get(struct gss_api_mech *);
128
129 /* Returns nonzero iff you've released the last reference to this mech.
130  * Note that for every succesful gss_get_mech call there must be exactly
131  * one corresponding call to gss_mech_put.*/
132 int gss_mech_put(struct gss_api_mech *);
133
134 #endif /* __KERNEL__ */
135 #endif /* _LINUX_SUNRPC_GSS_API_H */
136