xref: /netbsd-src/crypto/external/bsd/heimdal/dist/lib/krb5/init_creds.c (revision 241bea01a19bbb306af27777a870b86d41cb3fda)
1*241bea01Schristos /*	$NetBSD: init_creds.c,v 1.3 2019/12/15 22:50:50 christos Exp $	*/
2ca1c9b0cSelric 
3ca1c9b0cSelric /*
4ca1c9b0cSelric  * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan
5ca1c9b0cSelric  * (Royal Institute of Technology, Stockholm, Sweden).
6ca1c9b0cSelric  * All rights reserved.
7ca1c9b0cSelric  *
8ca1c9b0cSelric  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
9ca1c9b0cSelric  *
10ca1c9b0cSelric  * Redistribution and use in source and binary forms, with or without
11ca1c9b0cSelric  * modification, are permitted provided that the following conditions
12ca1c9b0cSelric  * are met:
13ca1c9b0cSelric  *
14ca1c9b0cSelric  * 1. Redistributions of source code must retain the above copyright
15ca1c9b0cSelric  *    notice, this list of conditions and the following disclaimer.
16ca1c9b0cSelric  *
17ca1c9b0cSelric  * 2. Redistributions in binary form must reproduce the above copyright
18ca1c9b0cSelric  *    notice, this list of conditions and the following disclaimer in the
19ca1c9b0cSelric  *    documentation and/or other materials provided with the distribution.
20ca1c9b0cSelric  *
21ca1c9b0cSelric  * 3. Neither the name of the Institute nor the names of its contributors
22ca1c9b0cSelric  *    may be used to endorse or promote products derived from this software
23ca1c9b0cSelric  *    without specific prior written permission.
24ca1c9b0cSelric  *
25ca1c9b0cSelric  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26ca1c9b0cSelric  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27ca1c9b0cSelric  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28ca1c9b0cSelric  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29ca1c9b0cSelric  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30ca1c9b0cSelric  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31ca1c9b0cSelric  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32ca1c9b0cSelric  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33ca1c9b0cSelric  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34ca1c9b0cSelric  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35ca1c9b0cSelric  * SUCH DAMAGE.
36ca1c9b0cSelric  */
37ca1c9b0cSelric 
38ca1c9b0cSelric #include "krb5_locl.h"
39ca1c9b0cSelric 
40ca1c9b0cSelric #undef __attribute__
41ca1c9b0cSelric #define __attribute__(x)
42ca1c9b0cSelric 
43ca1c9b0cSelric /**
44ca1c9b0cSelric  * @page krb5_init_creds_intro The initial credential handing functions
45ca1c9b0cSelric  * @section section_krb5_init_creds Initial credential
46ca1c9b0cSelric  *
47ca1c9b0cSelric  * Functions to get initial credentials: @ref krb5_credential .
48ca1c9b0cSelric  */
49ca1c9b0cSelric 
50ca1c9b0cSelric /**
51ca1c9b0cSelric  * Allocate a new krb5_get_init_creds_opt structure, free with
52ca1c9b0cSelric  * krb5_get_init_creds_opt_free().
53ca1c9b0cSelric  *
54ca1c9b0cSelric  * @ingroup krb5_credential
55ca1c9b0cSelric  */
56ca1c9b0cSelric 
57ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_alloc(krb5_context context,krb5_get_init_creds_opt ** opt)58ca1c9b0cSelric krb5_get_init_creds_opt_alloc(krb5_context context,
59ca1c9b0cSelric 			      krb5_get_init_creds_opt **opt)
60ca1c9b0cSelric {
61ca1c9b0cSelric     krb5_get_init_creds_opt *o;
62ca1c9b0cSelric 
63ca1c9b0cSelric     *opt = NULL;
64ca1c9b0cSelric     o = calloc(1, sizeof(*o));
65b9d004c6Schristos     if (o == NULL)
66b9d004c6Schristos 	return krb5_enomem(context);
67ca1c9b0cSelric 
68ca1c9b0cSelric     o->opt_private = calloc(1, sizeof(*o->opt_private));
69ca1c9b0cSelric     if (o->opt_private == NULL) {
70ca1c9b0cSelric 	free(o);
71b9d004c6Schristos 	return krb5_enomem(context);
72ca1c9b0cSelric     }
73ca1c9b0cSelric     o->opt_private->refcount = 1;
74ca1c9b0cSelric     *opt = o;
75ca1c9b0cSelric     return 0;
76ca1c9b0cSelric }
77ca1c9b0cSelric 
78ca1c9b0cSelric /**
79ca1c9b0cSelric  * Free krb5_get_init_creds_opt structure.
80ca1c9b0cSelric  *
81ca1c9b0cSelric  * @ingroup krb5_credential
82ca1c9b0cSelric  */
83ca1c9b0cSelric 
84ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_free(krb5_context context,krb5_get_init_creds_opt * opt)85ca1c9b0cSelric krb5_get_init_creds_opt_free(krb5_context context,
86ca1c9b0cSelric 			     krb5_get_init_creds_opt *opt)
87ca1c9b0cSelric {
88ca1c9b0cSelric     if (opt == NULL || opt->opt_private == NULL)
89ca1c9b0cSelric 	return;
90ca1c9b0cSelric     if (opt->opt_private->refcount < 1) /* abort ? */
91ca1c9b0cSelric 	return;
92ca1c9b0cSelric     if (--opt->opt_private->refcount == 0) {
93ca1c9b0cSelric 	_krb5_get_init_creds_opt_free_pkinit(opt);
94ca1c9b0cSelric 	free(opt->opt_private);
95ca1c9b0cSelric     }
96ca1c9b0cSelric     memset(opt, 0, sizeof(*opt));
97ca1c9b0cSelric     free(opt);
98ca1c9b0cSelric }
99ca1c9b0cSelric 
100ca1c9b0cSelric static int
get_config_time(krb5_context context,const char * realm,const char * name,int def)101ca1c9b0cSelric get_config_time (krb5_context context,
102ca1c9b0cSelric 		 const char *realm,
103ca1c9b0cSelric 		 const char *name,
104ca1c9b0cSelric 		 int def)
105ca1c9b0cSelric {
106ca1c9b0cSelric     int ret;
107ca1c9b0cSelric 
108ca1c9b0cSelric     ret = krb5_config_get_time (context, NULL,
109ca1c9b0cSelric 				"realms",
110ca1c9b0cSelric 				realm,
111ca1c9b0cSelric 				name,
112ca1c9b0cSelric 				NULL);
113ca1c9b0cSelric     if (ret >= 0)
114ca1c9b0cSelric 	return ret;
115ca1c9b0cSelric     ret = krb5_config_get_time (context, NULL,
116ca1c9b0cSelric 				"libdefaults",
117ca1c9b0cSelric 				name,
118ca1c9b0cSelric 				NULL);
119ca1c9b0cSelric     if (ret >= 0)
120ca1c9b0cSelric 	return ret;
121ca1c9b0cSelric     return def;
122ca1c9b0cSelric }
123ca1c9b0cSelric 
124ca1c9b0cSelric static krb5_boolean
get_config_bool(krb5_context context,krb5_boolean def_value,const char * realm,const char * name)125ca1c9b0cSelric get_config_bool (krb5_context context,
126ca1c9b0cSelric 		 krb5_boolean def_value,
127ca1c9b0cSelric 		 const char *realm,
128ca1c9b0cSelric 		 const char *name)
129ca1c9b0cSelric {
130ca1c9b0cSelric     krb5_boolean b;
131ca1c9b0cSelric 
132ca1c9b0cSelric     b = krb5_config_get_bool_default(context, NULL, def_value,
133ca1c9b0cSelric 				     "realms", realm, name, NULL);
134ca1c9b0cSelric     if (b != def_value)
135ca1c9b0cSelric 	return b;
136ca1c9b0cSelric     b = krb5_config_get_bool_default (context, NULL, def_value,
137ca1c9b0cSelric 				      "libdefaults", name, NULL);
138ca1c9b0cSelric     if (b != def_value)
139ca1c9b0cSelric 	return b;
140ca1c9b0cSelric     return def_value;
141ca1c9b0cSelric }
142ca1c9b0cSelric 
143ca1c9b0cSelric /*
144ca1c9b0cSelric  * set all the values in `opt' to the appropriate values for
145ca1c9b0cSelric  * application `appname' (default to getprogname() if NULL), and realm
146ca1c9b0cSelric  * `realm'.  First looks in [appdefaults] but falls back to
147ca1c9b0cSelric  * [realms] or [libdefaults] for some of the values.
148ca1c9b0cSelric  */
149ca1c9b0cSelric 
150ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_default_flags(krb5_context context,const char * appname,krb5_const_realm realm,krb5_get_init_creds_opt * opt)151ca1c9b0cSelric krb5_get_init_creds_opt_set_default_flags(krb5_context context,
152ca1c9b0cSelric 					  const char *appname,
153ca1c9b0cSelric 					  krb5_const_realm realm,
154ca1c9b0cSelric 					  krb5_get_init_creds_opt *opt)
155ca1c9b0cSelric {
156ca1c9b0cSelric     krb5_boolean b;
157ca1c9b0cSelric     time_t t;
158ca1c9b0cSelric 
159ca1c9b0cSelric     b = get_config_bool (context, KRB5_FORWARDABLE_DEFAULT,
160ca1c9b0cSelric 			 realm, "forwardable");
161ca1c9b0cSelric     krb5_appdefault_boolean(context, appname, realm, "forwardable", b, &b);
162ca1c9b0cSelric     krb5_get_init_creds_opt_set_forwardable(opt, b);
163ca1c9b0cSelric 
164ca1c9b0cSelric     b = get_config_bool (context, FALSE, realm, "proxiable");
165ca1c9b0cSelric     krb5_appdefault_boolean(context, appname, realm, "proxiable", b, &b);
166ca1c9b0cSelric     krb5_get_init_creds_opt_set_proxiable (opt, b);
167ca1c9b0cSelric 
168ca1c9b0cSelric     krb5_appdefault_time(context, appname, realm, "ticket_lifetime", 0, &t);
169ca1c9b0cSelric     if (t == 0)
170ca1c9b0cSelric 	t = get_config_time (context, realm, "ticket_lifetime", 0);
171ca1c9b0cSelric     if(t != 0)
172ca1c9b0cSelric 	krb5_get_init_creds_opt_set_tkt_life(opt, t);
173ca1c9b0cSelric 
174ca1c9b0cSelric     krb5_appdefault_time(context, appname, realm, "renew_lifetime", 0, &t);
175ca1c9b0cSelric     if (t == 0)
176ca1c9b0cSelric 	t = get_config_time (context, realm, "renew_lifetime", 0);
177ca1c9b0cSelric     if(t != 0)
178ca1c9b0cSelric 	krb5_get_init_creds_opt_set_renew_life(opt, t);
179ca1c9b0cSelric 
180ca1c9b0cSelric     krb5_appdefault_boolean(context, appname, realm, "no-addresses",
181ca1c9b0cSelric 			    KRB5_ADDRESSLESS_DEFAULT, &b);
182ca1c9b0cSelric     krb5_get_init_creds_opt_set_addressless (context, opt, b);
183ca1c9b0cSelric 
184ca1c9b0cSelric #if 0
185ca1c9b0cSelric     krb5_appdefault_boolean(context, appname, realm, "anonymous", FALSE, &b);
186ca1c9b0cSelric     krb5_get_init_creds_opt_set_anonymous (opt, b);
187ca1c9b0cSelric 
188ca1c9b0cSelric     krb5_get_init_creds_opt_set_etype_list(opt, enctype,
189ca1c9b0cSelric 					   etype_str.num_strings);
190ca1c9b0cSelric 
191ca1c9b0cSelric     krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt *opt,
192ca1c9b0cSelric 				     krb5_data *salt);
193ca1c9b0cSelric 
194ca1c9b0cSelric     krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt *opt,
195ca1c9b0cSelric 					     krb5_preauthtype *preauth_list,
196ca1c9b0cSelric 					     int preauth_list_length);
197ca1c9b0cSelric #endif
198ca1c9b0cSelric }
199ca1c9b0cSelric 
200b9d004c6Schristos KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_change_password_prompt(krb5_get_init_creds_opt * opt,int change_password_prompt)201b9d004c6Schristos krb5_get_init_creds_opt_set_change_password_prompt(krb5_get_init_creds_opt *opt,
202b9d004c6Schristos                                                    int change_password_prompt)
203b9d004c6Schristos {
204b9d004c6Schristos 	opt->flags |= KRB5_GET_INIT_CREDS_OPT_CHANGE_PASSWORD_PROMPT;
205b9d004c6Schristos 	opt->change_password_prompt = change_password_prompt;
206b9d004c6Schristos }
207ca1c9b0cSelric 
208ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt * opt,krb5_deltat tkt_life)209ca1c9b0cSelric krb5_get_init_creds_opt_set_tkt_life(krb5_get_init_creds_opt *opt,
210ca1c9b0cSelric 				     krb5_deltat tkt_life)
211ca1c9b0cSelric {
212ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_TKT_LIFE;
213ca1c9b0cSelric     opt->tkt_life = tkt_life;
214ca1c9b0cSelric }
215ca1c9b0cSelric 
216ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt * opt,krb5_deltat renew_life)217ca1c9b0cSelric krb5_get_init_creds_opt_set_renew_life(krb5_get_init_creds_opt *opt,
218ca1c9b0cSelric 				       krb5_deltat renew_life)
219ca1c9b0cSelric {
220ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE;
221ca1c9b0cSelric     opt->renew_life = renew_life;
222ca1c9b0cSelric }
223ca1c9b0cSelric 
224ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt * opt,int forwardable)225ca1c9b0cSelric krb5_get_init_creds_opt_set_forwardable(krb5_get_init_creds_opt *opt,
226ca1c9b0cSelric 					int forwardable)
227ca1c9b0cSelric {
228ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_FORWARDABLE;
229ca1c9b0cSelric     opt->forwardable = forwardable;
230ca1c9b0cSelric }
231ca1c9b0cSelric 
232ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt * opt,int proxiable)233ca1c9b0cSelric krb5_get_init_creds_opt_set_proxiable(krb5_get_init_creds_opt *opt,
234ca1c9b0cSelric 				      int proxiable)
235ca1c9b0cSelric {
236ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_PROXIABLE;
237ca1c9b0cSelric     opt->proxiable = proxiable;
238ca1c9b0cSelric }
239ca1c9b0cSelric 
240ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt * opt,krb5_enctype * etype_list,int etype_list_length)241ca1c9b0cSelric krb5_get_init_creds_opt_set_etype_list(krb5_get_init_creds_opt *opt,
242ca1c9b0cSelric 				       krb5_enctype *etype_list,
243ca1c9b0cSelric 				       int etype_list_length)
244ca1c9b0cSelric {
245ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST;
246ca1c9b0cSelric     opt->etype_list = etype_list;
247ca1c9b0cSelric     opt->etype_list_length = etype_list_length;
248ca1c9b0cSelric }
249ca1c9b0cSelric 
250ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt * opt,krb5_addresses * addresses)251ca1c9b0cSelric krb5_get_init_creds_opt_set_address_list(krb5_get_init_creds_opt *opt,
252ca1c9b0cSelric 					 krb5_addresses *addresses)
253ca1c9b0cSelric {
254ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST;
255ca1c9b0cSelric     opt->address_list = addresses;
256ca1c9b0cSelric }
257ca1c9b0cSelric 
258ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt * opt,krb5_preauthtype * preauth_list,int preauth_list_length)259ca1c9b0cSelric krb5_get_init_creds_opt_set_preauth_list(krb5_get_init_creds_opt *opt,
260ca1c9b0cSelric 					 krb5_preauthtype *preauth_list,
261ca1c9b0cSelric 					 int preauth_list_length)
262ca1c9b0cSelric {
263ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST;
264ca1c9b0cSelric     opt->preauth_list_length = preauth_list_length;
265ca1c9b0cSelric     opt->preauth_list = preauth_list;
266ca1c9b0cSelric }
267ca1c9b0cSelric 
268ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt * opt,krb5_data * salt)269ca1c9b0cSelric krb5_get_init_creds_opt_set_salt(krb5_get_init_creds_opt *opt,
270ca1c9b0cSelric 				 krb5_data *salt)
271ca1c9b0cSelric {
272ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_SALT;
273ca1c9b0cSelric     opt->salt = salt;
274ca1c9b0cSelric }
275ca1c9b0cSelric 
276ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt * opt,int anonymous)277ca1c9b0cSelric krb5_get_init_creds_opt_set_anonymous(krb5_get_init_creds_opt *opt,
278ca1c9b0cSelric 				      int anonymous)
279ca1c9b0cSelric {
280ca1c9b0cSelric     opt->flags |= KRB5_GET_INIT_CREDS_OPT_ANONYMOUS;
281ca1c9b0cSelric     opt->anonymous = anonymous;
282ca1c9b0cSelric }
283ca1c9b0cSelric 
284ca1c9b0cSelric static krb5_error_code
require_ext_opt(krb5_context context,krb5_get_init_creds_opt * opt,const char * type)285ca1c9b0cSelric require_ext_opt(krb5_context context,
286ca1c9b0cSelric 		krb5_get_init_creds_opt *opt,
287ca1c9b0cSelric 		const char *type)
288ca1c9b0cSelric {
289ca1c9b0cSelric     if (opt->opt_private == NULL) {
290ca1c9b0cSelric 	krb5_set_error_message(context, EINVAL,
291ca1c9b0cSelric 			       N_("%s on non extendable opt", ""), type);
292ca1c9b0cSelric 	return EINVAL;
293ca1c9b0cSelric     }
294ca1c9b0cSelric     return 0;
295ca1c9b0cSelric }
296ca1c9b0cSelric 
297ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_pa_password(krb5_context context,krb5_get_init_creds_opt * opt,const char * password,krb5_s2k_proc key_proc)298ca1c9b0cSelric krb5_get_init_creds_opt_set_pa_password(krb5_context context,
299ca1c9b0cSelric 					krb5_get_init_creds_opt *opt,
300ca1c9b0cSelric 					const char *password,
301ca1c9b0cSelric 					krb5_s2k_proc key_proc)
302ca1c9b0cSelric {
303ca1c9b0cSelric     krb5_error_code ret;
304ca1c9b0cSelric     ret = require_ext_opt(context, opt, "init_creds_opt_set_pa_password");
305ca1c9b0cSelric     if (ret)
306ca1c9b0cSelric 	return ret;
307ca1c9b0cSelric     opt->opt_private->password = password;
308ca1c9b0cSelric     opt->opt_private->key_proc = key_proc;
309ca1c9b0cSelric     return 0;
310ca1c9b0cSelric }
311ca1c9b0cSelric 
312ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_pac_request(krb5_context context,krb5_get_init_creds_opt * opt,krb5_boolean req_pac)313ca1c9b0cSelric krb5_get_init_creds_opt_set_pac_request(krb5_context context,
314ca1c9b0cSelric 					krb5_get_init_creds_opt *opt,
315ca1c9b0cSelric 					krb5_boolean req_pac)
316ca1c9b0cSelric {
317ca1c9b0cSelric     krb5_error_code ret;
318ca1c9b0cSelric     ret = require_ext_opt(context, opt, "init_creds_opt_set_pac_req");
319ca1c9b0cSelric     if (ret)
320ca1c9b0cSelric 	return ret;
321ca1c9b0cSelric     opt->opt_private->req_pac = req_pac ?
322ca1c9b0cSelric 	KRB5_INIT_CREDS_TRISTATE_TRUE :
323ca1c9b0cSelric 	KRB5_INIT_CREDS_TRISTATE_FALSE;
324ca1c9b0cSelric     return 0;
325ca1c9b0cSelric }
326ca1c9b0cSelric 
327ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_addressless(krb5_context context,krb5_get_init_creds_opt * opt,krb5_boolean addressless)328ca1c9b0cSelric krb5_get_init_creds_opt_set_addressless(krb5_context context,
329ca1c9b0cSelric 					krb5_get_init_creds_opt *opt,
330ca1c9b0cSelric 					krb5_boolean addressless)
331ca1c9b0cSelric {
332ca1c9b0cSelric     krb5_error_code ret;
333ca1c9b0cSelric     ret = require_ext_opt(context, opt, "init_creds_opt_set_pac_req");
334ca1c9b0cSelric     if (ret)
335ca1c9b0cSelric 	return ret;
336ca1c9b0cSelric     if (addressless)
337ca1c9b0cSelric 	opt->opt_private->addressless = KRB5_INIT_CREDS_TRISTATE_TRUE;
338ca1c9b0cSelric     else
339ca1c9b0cSelric 	opt->opt_private->addressless = KRB5_INIT_CREDS_TRISTATE_FALSE;
340ca1c9b0cSelric     return 0;
341ca1c9b0cSelric }
342ca1c9b0cSelric 
343ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_canonicalize(krb5_context context,krb5_get_init_creds_opt * opt,krb5_boolean req)344ca1c9b0cSelric krb5_get_init_creds_opt_set_canonicalize(krb5_context context,
345ca1c9b0cSelric 					 krb5_get_init_creds_opt *opt,
346ca1c9b0cSelric 					 krb5_boolean req)
347ca1c9b0cSelric {
348ca1c9b0cSelric     krb5_error_code ret;
349ca1c9b0cSelric     ret = require_ext_opt(context, opt, "init_creds_opt_set_canonicalize");
350ca1c9b0cSelric     if (ret)
351ca1c9b0cSelric 	return ret;
352ca1c9b0cSelric     if (req)
353ca1c9b0cSelric 	opt->opt_private->flags |= KRB5_INIT_CREDS_CANONICALIZE;
354ca1c9b0cSelric     else
355ca1c9b0cSelric 	opt->opt_private->flags &= ~KRB5_INIT_CREDS_CANONICALIZE;
356ca1c9b0cSelric     return 0;
357ca1c9b0cSelric }
358ca1c9b0cSelric 
359ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_win2k(krb5_context context,krb5_get_init_creds_opt * opt,krb5_boolean req)360ca1c9b0cSelric krb5_get_init_creds_opt_set_win2k(krb5_context context,
361ca1c9b0cSelric 				  krb5_get_init_creds_opt *opt,
362ca1c9b0cSelric 				  krb5_boolean req)
363ca1c9b0cSelric {
364ca1c9b0cSelric     krb5_error_code ret;
365ca1c9b0cSelric     ret = require_ext_opt(context, opt, "init_creds_opt_set_win2k");
366ca1c9b0cSelric     if (ret)
367ca1c9b0cSelric 	return ret;
368ca1c9b0cSelric     if (req) {
369ca1c9b0cSelric 	opt->opt_private->flags |= KRB5_INIT_CREDS_NO_C_CANON_CHECK;
370ca1c9b0cSelric 	opt->opt_private->flags |= KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK;
371*241bea01Schristos 	opt->opt_private->flags |= KRB5_INIT_CREDS_PKINIT_NO_KRBTGT_OTHERNAME_CHECK;
372ca1c9b0cSelric     } else {
373ca1c9b0cSelric 	opt->opt_private->flags &= ~KRB5_INIT_CREDS_NO_C_CANON_CHECK;
374ca1c9b0cSelric 	opt->opt_private->flags &= ~KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK;
375*241bea01Schristos 	opt->opt_private->flags &= ~KRB5_INIT_CREDS_PKINIT_NO_KRBTGT_OTHERNAME_CHECK;
376ca1c9b0cSelric     }
377ca1c9b0cSelric     return 0;
378ca1c9b0cSelric }
379ca1c9b0cSelric 
380ca1c9b0cSelric 
381ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_set_process_last_req(krb5_context context,krb5_get_init_creds_opt * opt,krb5_gic_process_last_req func,void * ctx)382ca1c9b0cSelric krb5_get_init_creds_opt_set_process_last_req(krb5_context context,
383ca1c9b0cSelric 					     krb5_get_init_creds_opt *opt,
384ca1c9b0cSelric 					     krb5_gic_process_last_req func,
385ca1c9b0cSelric 					     void *ctx)
386ca1c9b0cSelric {
387ca1c9b0cSelric     krb5_error_code ret;
388b9d004c6Schristos     ret = require_ext_opt(context, opt, "init_creds_opt_set_process_last_req");
389ca1c9b0cSelric     if (ret)
390ca1c9b0cSelric 	return ret;
391ca1c9b0cSelric 
392ca1c9b0cSelric     opt->opt_private->lr.func = func;
393ca1c9b0cSelric     opt->opt_private->lr.ctx = ctx;
394ca1c9b0cSelric 
395ca1c9b0cSelric     return 0;
396ca1c9b0cSelric }
397ca1c9b0cSelric 
398ca1c9b0cSelric 
399ca1c9b0cSelric #ifndef HEIMDAL_SMALLER
400ca1c9b0cSelric 
401ca1c9b0cSelric /**
402ca1c9b0cSelric  * Deprecated: use krb5_get_init_creds_opt_alloc().
403ca1c9b0cSelric  *
404ca1c9b0cSelric  * The reason krb5_get_init_creds_opt_init() is deprecated is that
405ca1c9b0cSelric  * krb5_get_init_creds_opt is a static structure and for ABI reason it
406ca1c9b0cSelric  * can't grow, ie can't add new functionality.
407ca1c9b0cSelric  *
408ca1c9b0cSelric  * @ingroup krb5_deprecated
409ca1c9b0cSelric  */
410ca1c9b0cSelric 
411ca1c9b0cSelric KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_get_init_creds_opt_init(krb5_get_init_creds_opt * opt)412ca1c9b0cSelric krb5_get_init_creds_opt_init(krb5_get_init_creds_opt *opt)
4134f77a458Spettai     KRB5_DEPRECATED_FUNCTION("Use X instead")
414ca1c9b0cSelric {
415ca1c9b0cSelric     memset (opt, 0, sizeof(*opt));
416ca1c9b0cSelric }
417ca1c9b0cSelric 
418ca1c9b0cSelric /**
419ca1c9b0cSelric  * Deprecated: use the new krb5_init_creds_init() and
420ca1c9b0cSelric  * krb5_init_creds_get_error().
421ca1c9b0cSelric  *
422ca1c9b0cSelric  * @ingroup krb5_deprecated
423ca1c9b0cSelric  */
424ca1c9b0cSelric 
425ca1c9b0cSelric KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_get_init_creds_opt_get_error(krb5_context context,krb5_get_init_creds_opt * opt,KRB_ERROR ** error)426ca1c9b0cSelric krb5_get_init_creds_opt_get_error(krb5_context context,
427ca1c9b0cSelric 				  krb5_get_init_creds_opt *opt,
428ca1c9b0cSelric 				  KRB_ERROR **error)
4294f77a458Spettai     KRB5_DEPRECATED_FUNCTION("Use X instead")
430ca1c9b0cSelric {
431ca1c9b0cSelric     *error = calloc(1, sizeof(**error));
432b9d004c6Schristos     if (*error == NULL)
433b9d004c6Schristos 	return krb5_enomem(context);
434ca1c9b0cSelric 
435ca1c9b0cSelric     return 0;
436ca1c9b0cSelric }
437ca1c9b0cSelric 
438ca1c9b0cSelric #endif /* HEIMDAL_SMALLER */
439