1*0a6a1f1dSLionel Sambuc /* $NetBSD: auth_context.c,v 1.3 2014/04/24 13:45:34 pettai Exp $ */
2ebfedea0SLionel Sambuc
3ebfedea0SLionel Sambuc /*
4ebfedea0SLionel Sambuc * Copyright (c) 1997 - 2002 Kungliga Tekniska Högskolan
5ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden).
6ebfedea0SLionel Sambuc * All rights reserved.
7ebfedea0SLionel Sambuc *
8ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without
9ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions
10ebfedea0SLionel Sambuc * are met:
11ebfedea0SLionel Sambuc *
12ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
13ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer.
14ebfedea0SLionel Sambuc *
15ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
16ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
17ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution.
18ebfedea0SLionel Sambuc *
19ebfedea0SLionel Sambuc * 3. Neither the name of the Institute nor the names of its contributors
20ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software
21ebfedea0SLionel Sambuc * without specific prior written permission.
22ebfedea0SLionel Sambuc *
23ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33ebfedea0SLionel Sambuc * SUCH DAMAGE.
34ebfedea0SLionel Sambuc */
35ebfedea0SLionel Sambuc
36ebfedea0SLionel Sambuc #include "krb5_locl.h"
37ebfedea0SLionel Sambuc
38ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_init(krb5_context context,krb5_auth_context * auth_context)39ebfedea0SLionel Sambuc krb5_auth_con_init(krb5_context context,
40ebfedea0SLionel Sambuc krb5_auth_context *auth_context)
41ebfedea0SLionel Sambuc {
42ebfedea0SLionel Sambuc krb5_auth_context p;
43ebfedea0SLionel Sambuc
44ebfedea0SLionel Sambuc ALLOC(p, 1);
45ebfedea0SLionel Sambuc if(!p) {
46ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
47ebfedea0SLionel Sambuc return ENOMEM;
48ebfedea0SLionel Sambuc }
49ebfedea0SLionel Sambuc memset(p, 0, sizeof(*p));
50ebfedea0SLionel Sambuc ALLOC(p->authenticator, 1);
51ebfedea0SLionel Sambuc if (!p->authenticator) {
52ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
53ebfedea0SLionel Sambuc free(p);
54ebfedea0SLionel Sambuc return ENOMEM;
55ebfedea0SLionel Sambuc }
56ebfedea0SLionel Sambuc memset (p->authenticator, 0, sizeof(*p->authenticator));
57ebfedea0SLionel Sambuc p->flags = KRB5_AUTH_CONTEXT_DO_TIME;
58ebfedea0SLionel Sambuc
59ebfedea0SLionel Sambuc p->local_address = NULL;
60ebfedea0SLionel Sambuc p->remote_address = NULL;
61ebfedea0SLionel Sambuc p->local_port = 0;
62ebfedea0SLionel Sambuc p->remote_port = 0;
63*0a6a1f1dSLionel Sambuc p->keytype = ENCTYPE_NULL;
64ebfedea0SLionel Sambuc p->cksumtype = CKSUMTYPE_NONE;
65ebfedea0SLionel Sambuc *auth_context = p;
66ebfedea0SLionel Sambuc return 0;
67ebfedea0SLionel Sambuc }
68ebfedea0SLionel Sambuc
69ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_free(krb5_context context,krb5_auth_context auth_context)70ebfedea0SLionel Sambuc krb5_auth_con_free(krb5_context context,
71ebfedea0SLionel Sambuc krb5_auth_context auth_context)
72ebfedea0SLionel Sambuc {
73ebfedea0SLionel Sambuc if (auth_context != NULL) {
74ebfedea0SLionel Sambuc krb5_free_authenticator(context, &auth_context->authenticator);
75ebfedea0SLionel Sambuc if(auth_context->local_address){
76ebfedea0SLionel Sambuc free_HostAddress(auth_context->local_address);
77ebfedea0SLionel Sambuc free(auth_context->local_address);
78ebfedea0SLionel Sambuc }
79ebfedea0SLionel Sambuc if(auth_context->remote_address){
80ebfedea0SLionel Sambuc free_HostAddress(auth_context->remote_address);
81ebfedea0SLionel Sambuc free(auth_context->remote_address);
82ebfedea0SLionel Sambuc }
83ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->keyblock);
84ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->remote_subkey);
85ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->local_subkey);
86ebfedea0SLionel Sambuc free (auth_context);
87ebfedea0SLionel Sambuc }
88ebfedea0SLionel Sambuc return 0;
89ebfedea0SLionel Sambuc }
90ebfedea0SLionel Sambuc
91ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setflags(krb5_context context,krb5_auth_context auth_context,int32_t flags)92ebfedea0SLionel Sambuc krb5_auth_con_setflags(krb5_context context,
93ebfedea0SLionel Sambuc krb5_auth_context auth_context,
94ebfedea0SLionel Sambuc int32_t flags)
95ebfedea0SLionel Sambuc {
96ebfedea0SLionel Sambuc auth_context->flags = flags;
97ebfedea0SLionel Sambuc return 0;
98ebfedea0SLionel Sambuc }
99ebfedea0SLionel Sambuc
100ebfedea0SLionel Sambuc
101ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getflags(krb5_context context,krb5_auth_context auth_context,int32_t * flags)102ebfedea0SLionel Sambuc krb5_auth_con_getflags(krb5_context context,
103ebfedea0SLionel Sambuc krb5_auth_context auth_context,
104ebfedea0SLionel Sambuc int32_t *flags)
105ebfedea0SLionel Sambuc {
106ebfedea0SLionel Sambuc *flags = auth_context->flags;
107ebfedea0SLionel Sambuc return 0;
108ebfedea0SLionel Sambuc }
109ebfedea0SLionel Sambuc
110ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_addflags(krb5_context context,krb5_auth_context auth_context,int32_t addflags,int32_t * flags)111ebfedea0SLionel Sambuc krb5_auth_con_addflags(krb5_context context,
112ebfedea0SLionel Sambuc krb5_auth_context auth_context,
113ebfedea0SLionel Sambuc int32_t addflags,
114ebfedea0SLionel Sambuc int32_t *flags)
115ebfedea0SLionel Sambuc {
116ebfedea0SLionel Sambuc if (flags)
117ebfedea0SLionel Sambuc *flags = auth_context->flags;
118ebfedea0SLionel Sambuc auth_context->flags |= addflags;
119ebfedea0SLionel Sambuc return 0;
120ebfedea0SLionel Sambuc }
121ebfedea0SLionel Sambuc
122ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_removeflags(krb5_context context,krb5_auth_context auth_context,int32_t removeflags,int32_t * flags)123ebfedea0SLionel Sambuc krb5_auth_con_removeflags(krb5_context context,
124ebfedea0SLionel Sambuc krb5_auth_context auth_context,
125ebfedea0SLionel Sambuc int32_t removeflags,
126ebfedea0SLionel Sambuc int32_t *flags)
127ebfedea0SLionel Sambuc {
128ebfedea0SLionel Sambuc if (flags)
129ebfedea0SLionel Sambuc *flags = auth_context->flags;
130ebfedea0SLionel Sambuc auth_context->flags &= ~removeflags;
131ebfedea0SLionel Sambuc return 0;
132ebfedea0SLionel Sambuc }
133ebfedea0SLionel Sambuc
134ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setaddrs(krb5_context context,krb5_auth_context auth_context,krb5_address * local_addr,krb5_address * remote_addr)135ebfedea0SLionel Sambuc krb5_auth_con_setaddrs(krb5_context context,
136ebfedea0SLionel Sambuc krb5_auth_context auth_context,
137ebfedea0SLionel Sambuc krb5_address *local_addr,
138ebfedea0SLionel Sambuc krb5_address *remote_addr)
139ebfedea0SLionel Sambuc {
140ebfedea0SLionel Sambuc if (local_addr) {
141ebfedea0SLionel Sambuc if (auth_context->local_address)
142ebfedea0SLionel Sambuc krb5_free_address (context, auth_context->local_address);
143ebfedea0SLionel Sambuc else
144ebfedea0SLionel Sambuc if ((auth_context->local_address = malloc(sizeof(krb5_address))) == NULL)
145ebfedea0SLionel Sambuc return ENOMEM;
146ebfedea0SLionel Sambuc krb5_copy_address(context, local_addr, auth_context->local_address);
147ebfedea0SLionel Sambuc }
148ebfedea0SLionel Sambuc if (remote_addr) {
149ebfedea0SLionel Sambuc if (auth_context->remote_address)
150ebfedea0SLionel Sambuc krb5_free_address (context, auth_context->remote_address);
151ebfedea0SLionel Sambuc else
152ebfedea0SLionel Sambuc if ((auth_context->remote_address = malloc(sizeof(krb5_address))) == NULL)
153ebfedea0SLionel Sambuc return ENOMEM;
154ebfedea0SLionel Sambuc krb5_copy_address(context, remote_addr, auth_context->remote_address);
155ebfedea0SLionel Sambuc }
156ebfedea0SLionel Sambuc return 0;
157ebfedea0SLionel Sambuc }
158ebfedea0SLionel Sambuc
159ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_genaddrs(krb5_context context,krb5_auth_context auth_context,krb5_socket_t fd,int flags)160ebfedea0SLionel Sambuc krb5_auth_con_genaddrs(krb5_context context,
161ebfedea0SLionel Sambuc krb5_auth_context auth_context,
162ebfedea0SLionel Sambuc krb5_socket_t fd, int flags)
163ebfedea0SLionel Sambuc {
164ebfedea0SLionel Sambuc krb5_error_code ret;
165ebfedea0SLionel Sambuc krb5_address local_k_address, remote_k_address;
166ebfedea0SLionel Sambuc krb5_address *lptr = NULL, *rptr = NULL;
167ebfedea0SLionel Sambuc struct sockaddr_storage ss_local, ss_remote;
168ebfedea0SLionel Sambuc struct sockaddr *local = (struct sockaddr *)&ss_local;
169ebfedea0SLionel Sambuc struct sockaddr *remote = (struct sockaddr *)&ss_remote;
170ebfedea0SLionel Sambuc socklen_t len;
171ebfedea0SLionel Sambuc
172ebfedea0SLionel Sambuc if(flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR) {
173ebfedea0SLionel Sambuc if (auth_context->local_address == NULL) {
174ebfedea0SLionel Sambuc len = sizeof(ss_local);
175ebfedea0SLionel Sambuc if(rk_IS_SOCKET_ERROR(getsockname(fd, local, &len))) {
176ebfedea0SLionel Sambuc char buf[128];
177ebfedea0SLionel Sambuc ret = rk_SOCK_ERRNO;
178ebfedea0SLionel Sambuc rk_strerror_r(ret, buf, sizeof(buf));
179ebfedea0SLionel Sambuc krb5_set_error_message(context, ret, "getsockname: %s", buf);
180ebfedea0SLionel Sambuc goto out;
181ebfedea0SLionel Sambuc }
182ebfedea0SLionel Sambuc ret = krb5_sockaddr2address (context, local, &local_k_address);
183ebfedea0SLionel Sambuc if(ret) goto out;
184ebfedea0SLionel Sambuc if(flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR) {
185ebfedea0SLionel Sambuc krb5_sockaddr2port (context, local, &auth_context->local_port);
186ebfedea0SLionel Sambuc } else
187ebfedea0SLionel Sambuc auth_context->local_port = 0;
188ebfedea0SLionel Sambuc lptr = &local_k_address;
189ebfedea0SLionel Sambuc }
190ebfedea0SLionel Sambuc }
191ebfedea0SLionel Sambuc if(flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR) {
192ebfedea0SLionel Sambuc len = sizeof(ss_remote);
193ebfedea0SLionel Sambuc if(rk_IS_SOCKET_ERROR(getpeername(fd, remote, &len))) {
194ebfedea0SLionel Sambuc char buf[128];
195ebfedea0SLionel Sambuc ret = rk_SOCK_ERRNO;
196ebfedea0SLionel Sambuc rk_strerror_r(ret, buf, sizeof(buf));
197ebfedea0SLionel Sambuc krb5_set_error_message(context, ret, "getpeername: %s", buf);
198ebfedea0SLionel Sambuc goto out;
199ebfedea0SLionel Sambuc }
200ebfedea0SLionel Sambuc ret = krb5_sockaddr2address (context, remote, &remote_k_address);
201ebfedea0SLionel Sambuc if(ret) goto out;
202ebfedea0SLionel Sambuc if(flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR) {
203ebfedea0SLionel Sambuc krb5_sockaddr2port (context, remote, &auth_context->remote_port);
204ebfedea0SLionel Sambuc } else
205ebfedea0SLionel Sambuc auth_context->remote_port = 0;
206ebfedea0SLionel Sambuc rptr = &remote_k_address;
207ebfedea0SLionel Sambuc }
208ebfedea0SLionel Sambuc ret = krb5_auth_con_setaddrs (context,
209ebfedea0SLionel Sambuc auth_context,
210ebfedea0SLionel Sambuc lptr,
211ebfedea0SLionel Sambuc rptr);
212ebfedea0SLionel Sambuc out:
213ebfedea0SLionel Sambuc if (lptr)
214ebfedea0SLionel Sambuc krb5_free_address (context, lptr);
215ebfedea0SLionel Sambuc if (rptr)
216ebfedea0SLionel Sambuc krb5_free_address (context, rptr);
217ebfedea0SLionel Sambuc return ret;
218ebfedea0SLionel Sambuc
219ebfedea0SLionel Sambuc }
220ebfedea0SLionel Sambuc
221ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setaddrs_from_fd(krb5_context context,krb5_auth_context auth_context,void * p_fd)222ebfedea0SLionel Sambuc krb5_auth_con_setaddrs_from_fd (krb5_context context,
223ebfedea0SLionel Sambuc krb5_auth_context auth_context,
224ebfedea0SLionel Sambuc void *p_fd)
225ebfedea0SLionel Sambuc {
226ebfedea0SLionel Sambuc krb5_socket_t fd = *(krb5_socket_t *)p_fd;
227ebfedea0SLionel Sambuc int flags = 0;
228ebfedea0SLionel Sambuc if(auth_context->local_address == NULL)
229ebfedea0SLionel Sambuc flags |= KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR;
230ebfedea0SLionel Sambuc if(auth_context->remote_address == NULL)
231ebfedea0SLionel Sambuc flags |= KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR;
232ebfedea0SLionel Sambuc return krb5_auth_con_genaddrs(context, auth_context, fd, flags);
233ebfedea0SLionel Sambuc }
234ebfedea0SLionel Sambuc
235ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getaddrs(krb5_context context,krb5_auth_context auth_context,krb5_address ** local_addr,krb5_address ** remote_addr)236ebfedea0SLionel Sambuc krb5_auth_con_getaddrs(krb5_context context,
237ebfedea0SLionel Sambuc krb5_auth_context auth_context,
238ebfedea0SLionel Sambuc krb5_address **local_addr,
239ebfedea0SLionel Sambuc krb5_address **remote_addr)
240ebfedea0SLionel Sambuc {
241ebfedea0SLionel Sambuc if(*local_addr)
242ebfedea0SLionel Sambuc krb5_free_address (context, *local_addr);
243ebfedea0SLionel Sambuc *local_addr = malloc (sizeof(**local_addr));
244ebfedea0SLionel Sambuc if (*local_addr == NULL) {
245ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
246ebfedea0SLionel Sambuc return ENOMEM;
247ebfedea0SLionel Sambuc }
248ebfedea0SLionel Sambuc krb5_copy_address(context,
249ebfedea0SLionel Sambuc auth_context->local_address,
250ebfedea0SLionel Sambuc *local_addr);
251ebfedea0SLionel Sambuc
252ebfedea0SLionel Sambuc if(*remote_addr)
253ebfedea0SLionel Sambuc krb5_free_address (context, *remote_addr);
254ebfedea0SLionel Sambuc *remote_addr = malloc (sizeof(**remote_addr));
255ebfedea0SLionel Sambuc if (*remote_addr == NULL) {
256ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
257ebfedea0SLionel Sambuc krb5_free_address (context, *local_addr);
258ebfedea0SLionel Sambuc *local_addr = NULL;
259ebfedea0SLionel Sambuc return ENOMEM;
260ebfedea0SLionel Sambuc }
261ebfedea0SLionel Sambuc krb5_copy_address(context,
262ebfedea0SLionel Sambuc auth_context->remote_address,
263ebfedea0SLionel Sambuc *remote_addr);
264ebfedea0SLionel Sambuc return 0;
265ebfedea0SLionel Sambuc }
266ebfedea0SLionel Sambuc
267ebfedea0SLionel Sambuc /* coverity[+alloc : arg-*2] */
268ebfedea0SLionel Sambuc static krb5_error_code
copy_key(krb5_context context,krb5_keyblock * in,krb5_keyblock ** out)269ebfedea0SLionel Sambuc copy_key(krb5_context context,
270ebfedea0SLionel Sambuc krb5_keyblock *in,
271ebfedea0SLionel Sambuc krb5_keyblock **out)
272ebfedea0SLionel Sambuc {
273ebfedea0SLionel Sambuc if(in)
274ebfedea0SLionel Sambuc return krb5_copy_keyblock(context, in, out);
275ebfedea0SLionel Sambuc *out = NULL; /* is this right? */
276ebfedea0SLionel Sambuc return 0;
277ebfedea0SLionel Sambuc }
278ebfedea0SLionel Sambuc
279ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock ** keyblock)280ebfedea0SLionel Sambuc krb5_auth_con_getkey(krb5_context context,
281ebfedea0SLionel Sambuc krb5_auth_context auth_context,
282ebfedea0SLionel Sambuc krb5_keyblock **keyblock)
283ebfedea0SLionel Sambuc {
284ebfedea0SLionel Sambuc return copy_key(context, auth_context->keyblock, keyblock);
285ebfedea0SLionel Sambuc }
286ebfedea0SLionel Sambuc
287ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getlocalsubkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock ** keyblock)288ebfedea0SLionel Sambuc krb5_auth_con_getlocalsubkey(krb5_context context,
289ebfedea0SLionel Sambuc krb5_auth_context auth_context,
290ebfedea0SLionel Sambuc krb5_keyblock **keyblock)
291ebfedea0SLionel Sambuc {
292ebfedea0SLionel Sambuc return copy_key(context, auth_context->local_subkey, keyblock);
293ebfedea0SLionel Sambuc }
294ebfedea0SLionel Sambuc
295ebfedea0SLionel Sambuc /* coverity[+alloc : arg-*2] */
296ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getremotesubkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock ** keyblock)297ebfedea0SLionel Sambuc krb5_auth_con_getremotesubkey(krb5_context context,
298ebfedea0SLionel Sambuc krb5_auth_context auth_context,
299ebfedea0SLionel Sambuc krb5_keyblock **keyblock)
300ebfedea0SLionel Sambuc {
301ebfedea0SLionel Sambuc return copy_key(context, auth_context->remote_subkey, keyblock);
302ebfedea0SLionel Sambuc }
303ebfedea0SLionel Sambuc
304ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock * keyblock)305ebfedea0SLionel Sambuc krb5_auth_con_setkey(krb5_context context,
306ebfedea0SLionel Sambuc krb5_auth_context auth_context,
307ebfedea0SLionel Sambuc krb5_keyblock *keyblock)
308ebfedea0SLionel Sambuc {
309ebfedea0SLionel Sambuc if(auth_context->keyblock)
310ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->keyblock);
311ebfedea0SLionel Sambuc return copy_key(context, keyblock, &auth_context->keyblock);
312ebfedea0SLionel Sambuc }
313ebfedea0SLionel Sambuc
314ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setlocalsubkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock * keyblock)315ebfedea0SLionel Sambuc krb5_auth_con_setlocalsubkey(krb5_context context,
316ebfedea0SLionel Sambuc krb5_auth_context auth_context,
317ebfedea0SLionel Sambuc krb5_keyblock *keyblock)
318ebfedea0SLionel Sambuc {
319ebfedea0SLionel Sambuc if(auth_context->local_subkey)
320ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->local_subkey);
321ebfedea0SLionel Sambuc return copy_key(context, keyblock, &auth_context->local_subkey);
322ebfedea0SLionel Sambuc }
323ebfedea0SLionel Sambuc
324ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_generatelocalsubkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock * key)325ebfedea0SLionel Sambuc krb5_auth_con_generatelocalsubkey(krb5_context context,
326ebfedea0SLionel Sambuc krb5_auth_context auth_context,
327ebfedea0SLionel Sambuc krb5_keyblock *key)
328ebfedea0SLionel Sambuc {
329ebfedea0SLionel Sambuc krb5_error_code ret;
330ebfedea0SLionel Sambuc krb5_keyblock *subkey;
331ebfedea0SLionel Sambuc
332ebfedea0SLionel Sambuc ret = krb5_generate_subkey_extended (context, key,
333ebfedea0SLionel Sambuc auth_context->keytype,
334ebfedea0SLionel Sambuc &subkey);
335ebfedea0SLionel Sambuc if(ret)
336ebfedea0SLionel Sambuc return ret;
337ebfedea0SLionel Sambuc if(auth_context->local_subkey)
338ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->local_subkey);
339ebfedea0SLionel Sambuc auth_context->local_subkey = subkey;
340ebfedea0SLionel Sambuc return 0;
341ebfedea0SLionel Sambuc }
342ebfedea0SLionel Sambuc
343ebfedea0SLionel Sambuc
344ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setremotesubkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock * keyblock)345ebfedea0SLionel Sambuc krb5_auth_con_setremotesubkey(krb5_context context,
346ebfedea0SLionel Sambuc krb5_auth_context auth_context,
347ebfedea0SLionel Sambuc krb5_keyblock *keyblock)
348ebfedea0SLionel Sambuc {
349ebfedea0SLionel Sambuc if(auth_context->remote_subkey)
350ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->remote_subkey);
351ebfedea0SLionel Sambuc return copy_key(context, keyblock, &auth_context->remote_subkey);
352ebfedea0SLionel Sambuc }
353ebfedea0SLionel Sambuc
354ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setcksumtype(krb5_context context,krb5_auth_context auth_context,krb5_cksumtype cksumtype)355ebfedea0SLionel Sambuc krb5_auth_con_setcksumtype(krb5_context context,
356ebfedea0SLionel Sambuc krb5_auth_context auth_context,
357ebfedea0SLionel Sambuc krb5_cksumtype cksumtype)
358ebfedea0SLionel Sambuc {
359ebfedea0SLionel Sambuc auth_context->cksumtype = cksumtype;
360ebfedea0SLionel Sambuc return 0;
361ebfedea0SLionel Sambuc }
362ebfedea0SLionel Sambuc
363ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getcksumtype(krb5_context context,krb5_auth_context auth_context,krb5_cksumtype * cksumtype)364ebfedea0SLionel Sambuc krb5_auth_con_getcksumtype(krb5_context context,
365ebfedea0SLionel Sambuc krb5_auth_context auth_context,
366ebfedea0SLionel Sambuc krb5_cksumtype *cksumtype)
367ebfedea0SLionel Sambuc {
368ebfedea0SLionel Sambuc *cksumtype = auth_context->cksumtype;
369ebfedea0SLionel Sambuc return 0;
370ebfedea0SLionel Sambuc }
371ebfedea0SLionel Sambuc
372ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setkeytype(krb5_context context,krb5_auth_context auth_context,krb5_keytype keytype)373ebfedea0SLionel Sambuc krb5_auth_con_setkeytype (krb5_context context,
374ebfedea0SLionel Sambuc krb5_auth_context auth_context,
375ebfedea0SLionel Sambuc krb5_keytype keytype)
376ebfedea0SLionel Sambuc {
377ebfedea0SLionel Sambuc auth_context->keytype = keytype;
378ebfedea0SLionel Sambuc return 0;
379ebfedea0SLionel Sambuc }
380ebfedea0SLionel Sambuc
381ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getkeytype(krb5_context context,krb5_auth_context auth_context,krb5_keytype * keytype)382ebfedea0SLionel Sambuc krb5_auth_con_getkeytype (krb5_context context,
383ebfedea0SLionel Sambuc krb5_auth_context auth_context,
384ebfedea0SLionel Sambuc krb5_keytype *keytype)
385ebfedea0SLionel Sambuc {
386ebfedea0SLionel Sambuc *keytype = auth_context->keytype;
387ebfedea0SLionel Sambuc return 0;
388ebfedea0SLionel Sambuc }
389ebfedea0SLionel Sambuc
390ebfedea0SLionel Sambuc #if 0
391ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
392ebfedea0SLionel Sambuc krb5_auth_con_setenctype(krb5_context context,
393ebfedea0SLionel Sambuc krb5_auth_context auth_context,
394ebfedea0SLionel Sambuc krb5_enctype etype)
395ebfedea0SLionel Sambuc {
396ebfedea0SLionel Sambuc if(auth_context->keyblock)
397ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->keyblock);
398ebfedea0SLionel Sambuc ALLOC(auth_context->keyblock, 1);
399ebfedea0SLionel Sambuc if(auth_context->keyblock == NULL)
400ebfedea0SLionel Sambuc return ENOMEM;
401ebfedea0SLionel Sambuc auth_context->keyblock->keytype = etype;
402ebfedea0SLionel Sambuc return 0;
403ebfedea0SLionel Sambuc }
404ebfedea0SLionel Sambuc
405ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
406ebfedea0SLionel Sambuc krb5_auth_con_getenctype(krb5_context context,
407ebfedea0SLionel Sambuc krb5_auth_context auth_context,
408ebfedea0SLionel Sambuc krb5_enctype *etype)
409ebfedea0SLionel Sambuc {
410ebfedea0SLionel Sambuc krb5_abortx(context, "unimplemented krb5_auth_getenctype called");
411ebfedea0SLionel Sambuc }
412ebfedea0SLionel Sambuc #endif
413ebfedea0SLionel Sambuc
414ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getlocalseqnumber(krb5_context context,krb5_auth_context auth_context,int32_t * seqnumber)415ebfedea0SLionel Sambuc krb5_auth_con_getlocalseqnumber(krb5_context context,
416ebfedea0SLionel Sambuc krb5_auth_context auth_context,
417ebfedea0SLionel Sambuc int32_t *seqnumber)
418ebfedea0SLionel Sambuc {
419ebfedea0SLionel Sambuc *seqnumber = auth_context->local_seqnumber;
420ebfedea0SLionel Sambuc return 0;
421ebfedea0SLionel Sambuc }
422ebfedea0SLionel Sambuc
423ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setlocalseqnumber(krb5_context context,krb5_auth_context auth_context,int32_t seqnumber)424ebfedea0SLionel Sambuc krb5_auth_con_setlocalseqnumber (krb5_context context,
425ebfedea0SLionel Sambuc krb5_auth_context auth_context,
426ebfedea0SLionel Sambuc int32_t seqnumber)
427ebfedea0SLionel Sambuc {
428ebfedea0SLionel Sambuc auth_context->local_seqnumber = seqnumber;
429ebfedea0SLionel Sambuc return 0;
430ebfedea0SLionel Sambuc }
431ebfedea0SLionel Sambuc
432ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getremoteseqnumber(krb5_context context,krb5_auth_context auth_context,int32_t * seqnumber)433ebfedea0SLionel Sambuc krb5_auth_con_getremoteseqnumber(krb5_context context,
434ebfedea0SLionel Sambuc krb5_auth_context auth_context,
435ebfedea0SLionel Sambuc int32_t *seqnumber)
436ebfedea0SLionel Sambuc {
437ebfedea0SLionel Sambuc *seqnumber = auth_context->remote_seqnumber;
438ebfedea0SLionel Sambuc return 0;
439ebfedea0SLionel Sambuc }
440ebfedea0SLionel Sambuc
441ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setremoteseqnumber(krb5_context context,krb5_auth_context auth_context,int32_t seqnumber)442ebfedea0SLionel Sambuc krb5_auth_con_setremoteseqnumber (krb5_context context,
443ebfedea0SLionel Sambuc krb5_auth_context auth_context,
444ebfedea0SLionel Sambuc int32_t seqnumber)
445ebfedea0SLionel Sambuc {
446ebfedea0SLionel Sambuc auth_context->remote_seqnumber = seqnumber;
447ebfedea0SLionel Sambuc return 0;
448ebfedea0SLionel Sambuc }
449ebfedea0SLionel Sambuc
450ebfedea0SLionel Sambuc
451ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getauthenticator(krb5_context context,krb5_auth_context auth_context,krb5_authenticator * authenticator)452ebfedea0SLionel Sambuc krb5_auth_con_getauthenticator(krb5_context context,
453ebfedea0SLionel Sambuc krb5_auth_context auth_context,
454ebfedea0SLionel Sambuc krb5_authenticator *authenticator)
455ebfedea0SLionel Sambuc {
456ebfedea0SLionel Sambuc *authenticator = malloc(sizeof(**authenticator));
457ebfedea0SLionel Sambuc if (*authenticator == NULL) {
458ebfedea0SLionel Sambuc krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
459ebfedea0SLionel Sambuc return ENOMEM;
460ebfedea0SLionel Sambuc }
461ebfedea0SLionel Sambuc
462ebfedea0SLionel Sambuc copy_Authenticator(auth_context->authenticator,
463ebfedea0SLionel Sambuc *authenticator);
464ebfedea0SLionel Sambuc return 0;
465ebfedea0SLionel Sambuc }
466ebfedea0SLionel Sambuc
467ebfedea0SLionel Sambuc
468ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_free_authenticator(krb5_context context,krb5_authenticator * authenticator)469ebfedea0SLionel Sambuc krb5_free_authenticator(krb5_context context,
470ebfedea0SLionel Sambuc krb5_authenticator *authenticator)
471ebfedea0SLionel Sambuc {
472ebfedea0SLionel Sambuc free_Authenticator (*authenticator);
473ebfedea0SLionel Sambuc free (*authenticator);
474ebfedea0SLionel Sambuc *authenticator = NULL;
475ebfedea0SLionel Sambuc }
476ebfedea0SLionel Sambuc
477ebfedea0SLionel Sambuc
478ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setuserkey(krb5_context context,krb5_auth_context auth_context,krb5_keyblock * keyblock)479ebfedea0SLionel Sambuc krb5_auth_con_setuserkey(krb5_context context,
480ebfedea0SLionel Sambuc krb5_auth_context auth_context,
481ebfedea0SLionel Sambuc krb5_keyblock *keyblock)
482ebfedea0SLionel Sambuc {
483ebfedea0SLionel Sambuc if(auth_context->keyblock)
484ebfedea0SLionel Sambuc krb5_free_keyblock(context, auth_context->keyblock);
485ebfedea0SLionel Sambuc return krb5_copy_keyblock(context, keyblock, &auth_context->keyblock);
486ebfedea0SLionel Sambuc }
487ebfedea0SLionel Sambuc
488ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_getrcache(krb5_context context,krb5_auth_context auth_context,krb5_rcache * rcache)489ebfedea0SLionel Sambuc krb5_auth_con_getrcache(krb5_context context,
490ebfedea0SLionel Sambuc krb5_auth_context auth_context,
491ebfedea0SLionel Sambuc krb5_rcache *rcache)
492ebfedea0SLionel Sambuc {
493ebfedea0SLionel Sambuc *rcache = auth_context->rcache;
494ebfedea0SLionel Sambuc return 0;
495ebfedea0SLionel Sambuc }
496ebfedea0SLionel Sambuc
497ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_auth_con_setrcache(krb5_context context,krb5_auth_context auth_context,krb5_rcache rcache)498ebfedea0SLionel Sambuc krb5_auth_con_setrcache(krb5_context context,
499ebfedea0SLionel Sambuc krb5_auth_context auth_context,
500ebfedea0SLionel Sambuc krb5_rcache rcache)
501ebfedea0SLionel Sambuc {
502ebfedea0SLionel Sambuc auth_context->rcache = rcache;
503ebfedea0SLionel Sambuc return 0;
504ebfedea0SLionel Sambuc }
505ebfedea0SLionel Sambuc
506ebfedea0SLionel Sambuc #if 0 /* not implemented */
507ebfedea0SLionel Sambuc
508ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
509ebfedea0SLionel Sambuc krb5_auth_con_initivector(krb5_context context,
510ebfedea0SLionel Sambuc krb5_auth_context auth_context)
511ebfedea0SLionel Sambuc {
512ebfedea0SLionel Sambuc krb5_abortx(context, "unimplemented krb5_auth_con_initivector called");
513ebfedea0SLionel Sambuc }
514ebfedea0SLionel Sambuc
515ebfedea0SLionel Sambuc
516ebfedea0SLionel Sambuc KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
517ebfedea0SLionel Sambuc krb5_auth_con_setivector(krb5_context context,
518ebfedea0SLionel Sambuc krb5_auth_context auth_context,
519ebfedea0SLionel Sambuc krb5_pointer ivector)
520ebfedea0SLionel Sambuc {
521ebfedea0SLionel Sambuc krb5_abortx(context, "unimplemented krb5_auth_con_setivector called");
522ebfedea0SLionel Sambuc }
523ebfedea0SLionel Sambuc
524ebfedea0SLionel Sambuc #endif /* not implemented */
525