Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / nfs-utils / utils / gssd / context_spkm3.c
blobb927475c63692a7a5a6a1565151013595d83b643
1 /*
2 Copyright (c) 2004 The Regents of the University of Michigan.
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:
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 2. Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
14 3. Neither the name of the University nor the names of its
15 contributors may be used to endorse or promote products derived
16 from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif /* HAVE_CONFIG_H */
35 #include <stdio.h>
36 #include <syslog.h>
37 #include <string.h>
38 #include <gssapi/gssapi.h>
39 #include <rpc/rpc.h>
40 #include <rpc/auth_gss.h>
41 #include "gss_util.h"
42 #include "gss_oids.h"
43 #include "err_util.h"
44 #include "context.h"
46 #ifdef HAVE_SPKM3_H
48 #include <spkm3.h>
51 * Function: prepare_spkm3_ctx_buffer()
53 * Prepare spkm3 lucid context for the kernel
55 * buf->length should be:
57 * version 4
58 * ctx_id 4 + 12
59 * qop 4
60 * mech_used 4 + 7
61 * ret_fl 4
62 * req_fl 4
63 * share 4 + key_len
64 * conf_alg 4 + oid_len
65 * d_conf_key 4 + key_len
66 * intg_alg 4 + oid_len
67 * d_intg_key 4 + key_len
68 * kyestb 4 + oid_len
69 * owl alg 4 + oid_len
71 static int
72 prepare_spkm3_ctx_buffer(gss_spkm3_lucid_ctx_t *lctx, gss_buffer_desc *buf)
74 char *p, *end;
75 unsigned int buf_size = 0;
77 buf_size = sizeof(lctx->version) +
78 lctx->ctx_id.length + sizeof(lctx->ctx_id.length) +
79 sizeof(lctx->endtime) +
80 sizeof(lctx->mech_used.length) + lctx->mech_used.length +
81 sizeof(lctx->ret_flags) +
82 sizeof(lctx->conf_alg.length) + lctx->conf_alg.length +
83 sizeof(lctx->derived_conf_key.length) +
84 lctx->derived_conf_key.length +
85 sizeof(lctx->intg_alg.length) + lctx->intg_alg.length +
86 sizeof(lctx->derived_integ_key.length) +
87 lctx->derived_integ_key.length;
89 if (!(buf->value = calloc(1, buf_size)))
90 goto out_err;
91 p = buf->value;
92 end = buf->value + buf_size;
94 if (WRITE_BYTES(&p, end, lctx->version))
95 goto out_err;
96 printerr(2, "DEBUG: exporting version = %d\n", lctx->version);
98 if (write_buffer(&p, end, &lctx->ctx_id))
99 goto out_err;
100 printerr(2, "DEBUG: exporting ctx_id(%d)\n", lctx->ctx_id.length);
102 if (WRITE_BYTES(&p, end, lctx->endtime))
103 goto out_err;
104 printerr(2, "DEBUG: exporting endtime = %d\n", lctx->endtime);
106 if (write_buffer(&p, end, &lctx->mech_used))
107 goto out_err;
108 printerr(2, "DEBUG: exporting mech oid (%d)\n", lctx->mech_used.length);
110 if (WRITE_BYTES(&p, end, lctx->ret_flags))
111 goto out_err;
112 printerr(2, "DEBUG: exporting ret_flags = %d\n", lctx->ret_flags);
114 if (write_buffer(&p, end, &lctx->conf_alg))
115 goto out_err;
116 printerr(2, "DEBUG: exporting conf_alg oid (%d)\n", lctx->conf_alg.length);
118 if (write_buffer(&p, end, &lctx->derived_conf_key))
119 goto out_err;
120 printerr(2, "DEBUG: exporting conf key (%d)\n", lctx->derived_conf_key.length);
122 if (write_buffer(&p, end, &lctx->intg_alg))
123 goto out_err;
124 printerr(2, "DEBUG: exporting intg_alg oid (%d)\n", lctx->intg_alg.length);
126 if (write_buffer(&p, end, &lctx->derived_integ_key))
127 goto out_err;
128 printerr(2, "DEBUG: exporting intg key (%d)\n", lctx->derived_integ_key.length);
130 buf->length = p - (char *)buf->value;
131 return 0;
132 out_err:
133 printerr(0, "ERROR: failed serializing spkm3 context for kernel\n");
134 if (buf->value) free(buf->value);
135 buf->length = 0;
137 return -1;
140 /* ANDROS: need to determine which fields of the spkm3_gss_ctx_id_desc_t
141 * are needed in the kernel for get_mic, validate, wrap, unwrap, and destroy
142 * and only export those fields to the kernel.
145 serialize_spkm3_ctx(gss_ctx_id_t ctx, gss_buffer_desc *buf, int32_t *endtime)
147 OM_uint32 vers, ret, maj_stat, min_stat;
148 void *ret_ctx = 0;
149 gss_spkm3_lucid_ctx_t *lctx;
151 printerr(1, "serialize_spkm3_ctx called\n");
153 printerr(2, "DEBUG: serialize_spkm3_ctx: lucid version!\n");
154 maj_stat = gss_export_lucid_sec_context(&min_stat, &ctx, 1, &ret_ctx);
155 if (maj_stat != GSS_S_COMPLETE)
156 goto out_err;
158 lctx = (gss_spkm3_lucid_ctx_t *)ret_ctx;
160 vers = lctx->version;
161 if (vers != 1) {
162 printerr(0, "ERROR: unsupported spkm3 context version %d\n",
163 vers);
164 goto out_err;
166 ret = prepare_spkm3_ctx_buffer(lctx, buf);
168 if (endtime)
169 *endtime = lctx->endtime;
171 maj_stat = gss_free_lucid_sec_context(&min_stat, ctx, ret_ctx);
173 if (maj_stat != GSS_S_COMPLETE)
174 printerr(0, "WARN: failed to free lucid sec context\n");
175 if (ret)
176 goto out_err;
177 printerr(2, "DEBUG: serialize_spkm3_ctx: success\n");
178 return 0;
180 out_err:
181 printerr(2, "DEBUG: serialize_spkm3_ctx: failed\n");
182 return -1;
184 #endif /* HAVE_SPKM3_H */