2 * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
37 #define __attribute__(x)
40 * @page krb5_init_creds_intro The initial credential handing functions
41 * @section section_krb5_init_creds Initial credential
43 * Functions to get initial credentials: @ref krb5_credential .
47 * Allocate a new krb5_get_init_creds_opt structure, free with
48 * krb5_get_init_creds_opt_free().
50 * @ingroup krb5_credential
53 krb5_error_code KRB5_LIB_FUNCTION
54 krb5_get_init_creds_opt_alloc(krb5_context context
,
55 krb5_get_init_creds_opt
**opt
)
57 krb5_get_init_creds_opt
*o
;
60 o
= calloc(1, sizeof(*o
));
62 krb5_set_error_message(context
, ENOMEM
,
63 N_("malloc: out of memory", ""));
67 o
->opt_private
= calloc(1, sizeof(*o
->opt_private
));
68 if (o
->opt_private
== NULL
) {
69 krb5_set_error_message(context
, ENOMEM
,
70 N_("malloc: out of memory", ""));
74 o
->opt_private
->refcount
= 1;
80 * Free krb5_get_init_creds_opt structure.
82 * @ingroup krb5_credential
85 void KRB5_LIB_FUNCTION
86 krb5_get_init_creds_opt_free(krb5_context context
,
87 krb5_get_init_creds_opt
*opt
)
89 if (opt
== NULL
|| opt
->opt_private
== NULL
)
91 if (opt
->opt_private
->refcount
< 1) /* abort ? */
93 if (--opt
->opt_private
->refcount
== 0) {
94 _krb5_get_init_creds_opt_free_pkinit(opt
);
95 free(opt
->opt_private
);
97 memset(opt
, 0, sizeof(*opt
));
102 get_config_time (krb5_context context
,
109 ret
= krb5_config_get_time (context
, NULL
,
116 ret
= krb5_config_get_time (context
, NULL
,
126 get_config_bool (krb5_context context
,
130 return krb5_config_get_bool (context
,
136 || krb5_config_get_bool (context
,
144 * set all the values in `opt' to the appropriate values for
145 * application `appname' (default to getprogname() if NULL), and realm
146 * `realm'. First looks in [appdefaults] but falls back to
147 * [realms] or [libdefaults] for some of the values.
150 void KRB5_LIB_FUNCTION
151 krb5_get_init_creds_opt_set_default_flags(krb5_context context
,
153 krb5_const_realm realm
,
154 krb5_get_init_creds_opt
*opt
)
159 b
= get_config_bool (context
, realm
, "forwardable");
160 krb5_appdefault_boolean(context
, appname
, realm
, "forwardable", b
, &b
);
161 krb5_get_init_creds_opt_set_forwardable(opt
, b
);
163 b
= get_config_bool (context
, realm
, "proxiable");
164 krb5_appdefault_boolean(context
, appname
, realm
, "proxiable", b
, &b
);
165 krb5_get_init_creds_opt_set_proxiable (opt
, b
);
167 krb5_appdefault_time(context
, appname
, realm
, "ticket_lifetime", 0, &t
);
169 t
= get_config_time (context
, realm
, "ticket_lifetime", 0);
171 krb5_get_init_creds_opt_set_tkt_life(opt
, t
);
173 krb5_appdefault_time(context
, appname
, realm
, "renew_lifetime", 0, &t
);
175 t
= get_config_time (context
, realm
, "renew_lifetime", 0);
177 krb5_get_init_creds_opt_set_renew_life(opt
, t
);
179 krb5_appdefault_boolean(context
, appname
, realm
, "no-addresses",
180 KRB5_ADDRESSLESS_DEFAULT
, &b
);
181 krb5_get_init_creds_opt_set_addressless (context
, opt
, b
);
184 krb5_appdefault_boolean(context
, appname
, realm
, "anonymous", FALSE
, &b
);
185 krb5_get_init_creds_opt_set_anonymous (opt
, b
);
187 krb5_get_init_creds_opt_set_etype_list(opt
, enctype
,
188 etype_str
.num_strings
);
190 krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt
*opt
,
193 krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt
*opt
,
194 krb5_preauthtype
*preauth_list
,
195 int preauth_list_length
);
200 void KRB5_LIB_FUNCTION
201 krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt
*opt
,
202 krb5_deltat tkt_life
)
204 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_TKT_LIFE
;
205 opt
->tkt_life
= tkt_life
;
208 void KRB5_LIB_FUNCTION
209 krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt
*opt
,
210 krb5_deltat renew_life
)
212 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE
;
213 opt
->renew_life
= renew_life
;
216 void KRB5_LIB_FUNCTION
217 krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt
*opt
,
220 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_FORWARDABLE
;
221 opt
->forwardable
= forwardable
;
224 void KRB5_LIB_FUNCTION
225 krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt
*opt
,
228 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_PROXIABLE
;
229 opt
->proxiable
= proxiable
;
232 void KRB5_LIB_FUNCTION
233 krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt
*opt
,
234 krb5_enctype
*etype_list
,
235 int etype_list_length
)
237 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST
;
238 opt
->etype_list
= etype_list
;
239 opt
->etype_list_length
= etype_list_length
;
242 void KRB5_LIB_FUNCTION
243 krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt
*opt
,
244 krb5_addresses
*addresses
)
246 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST
;
247 opt
->address_list
= addresses
;
250 void KRB5_LIB_FUNCTION
251 krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt
*opt
,
252 krb5_preauthtype
*preauth_list
,
253 int preauth_list_length
)
255 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST
;
256 opt
->preauth_list_length
= preauth_list_length
;
257 opt
->preauth_list
= preauth_list
;
260 void KRB5_LIB_FUNCTION
261 krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt
*opt
,
264 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_SALT
;
268 void KRB5_LIB_FUNCTION
269 krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt
*opt
,
272 opt
->flags
|= KRB5_GET_INIT_CREDS_OPT_ANONYMOUS
;
273 opt
->anonymous
= anonymous
;
276 static krb5_error_code
277 require_ext_opt(krb5_context context
,
278 krb5_get_init_creds_opt
*opt
,
281 if (opt
->opt_private
== NULL
) {
282 krb5_set_error_message(context
, EINVAL
,
283 N_("%s on non extendable opt", ""), type
);
289 krb5_error_code KRB5_LIB_FUNCTION
290 krb5_get_init_creds_opt_set_pa_password(krb5_context context
,
291 krb5_get_init_creds_opt
*opt
,
292 const char *password
,
293 krb5_s2k_proc key_proc
)
296 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_pa_password");
299 opt
->opt_private
->password
= password
;
300 opt
->opt_private
->key_proc
= key_proc
;
304 krb5_error_code KRB5_LIB_FUNCTION
305 krb5_get_init_creds_opt_set_pac_request(krb5_context context
,
306 krb5_get_init_creds_opt
*opt
,
307 krb5_boolean req_pac
)
310 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_pac_req");
313 opt
->opt_private
->req_pac
= req_pac
?
314 KRB5_INIT_CREDS_TRISTATE_TRUE
:
315 KRB5_INIT_CREDS_TRISTATE_FALSE
;
319 krb5_error_code KRB5_LIB_FUNCTION
320 krb5_get_init_creds_opt_set_addressless(krb5_context context
,
321 krb5_get_init_creds_opt
*opt
,
322 krb5_boolean addressless
)
325 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_pac_req");
329 opt
->opt_private
->addressless
= KRB5_INIT_CREDS_TRISTATE_TRUE
;
331 opt
->opt_private
->addressless
= KRB5_INIT_CREDS_TRISTATE_FALSE
;
335 krb5_error_code KRB5_LIB_FUNCTION
336 krb5_get_init_creds_opt_set_canonicalize(krb5_context context
,
337 krb5_get_init_creds_opt
*opt
,
341 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_canonicalize");
345 opt
->opt_private
->flags
|= KRB5_INIT_CREDS_CANONICALIZE
;
347 opt
->opt_private
->flags
&= ~KRB5_INIT_CREDS_CANONICALIZE
;
351 krb5_error_code KRB5_LIB_FUNCTION
352 krb5_get_init_creds_opt_set_win2k(krb5_context context
,
353 krb5_get_init_creds_opt
*opt
,
357 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_win2k");
361 opt
->opt_private
->flags
|= KRB5_INIT_CREDS_NO_C_CANON_CHECK
;
363 opt
->opt_private
->flags
&= ~KRB5_INIT_CREDS_NO_C_CANON_CHECK
;
368 krb5_error_code KRB5_LIB_FUNCTION
369 krb5_get_init_creds_opt_set_process_last_req(krb5_context context
,
370 krb5_get_init_creds_opt
*opt
,
371 krb5_gic_process_last_req func
,
375 ret
= require_ext_opt(context
, opt
, "init_creds_opt_set_win2k");
379 opt
->opt_private
->lr
.func
= func
;
380 opt
->opt_private
->lr
.ctx
= ctx
;
386 #ifndef HEIMDAL_SMALLER
389 * Deprecated: use krb5_get_init_creds_opt_alloc().
391 * The reason krb5_get_init_creds_opt_init() is deprecated is that
392 * krb5_get_init_creds_opt is a static structure and for ABI reason it
393 * can't grow, ie can't add new functionality.
395 * @ingroup krb5_deprecated
398 void KRB5_LIB_FUNCTION
399 krb5_get_init_creds_opt_init(krb5_get_init_creds_opt
*opt
)
402 memset (opt
, 0, sizeof(*opt
));
406 * Deprecated: use the new krb5_init_creds_init() and
407 * krb5_init_creds_get_error().
409 * @ingroup krb5_deprecated
412 krb5_error_code KRB5_LIB_FUNCTION
413 krb5_get_init_creds_opt_get_error(krb5_context context
,
414 krb5_get_init_creds_opt
*opt
,
418 *error
= calloc(1, sizeof(**error
));
419 if (*error
== NULL
) {
420 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
427 #endif /* HEIMDAL_SMALLER */