Branch data Line data Source code
1 : : /* cfg.h --- Configuration file functions.
2 : : * Copyright (C) 2002, 2003, 2004, 2006, 2007, 2008, 2010 Simon Josefsson
3 : : *
4 : : * This file is part of Shishi.
5 : : *
6 : : * Shishi is free software; you can redistribute it and/or modify it
7 : : * under the terms of the GNU General Public License as published by
8 : : * the Free Software Foundation; either version 3 of the License, or
9 : : * (at your option) any later version.
10 : : *
11 : : * Shishi is distributed in the hope that it will be useful, but
12 : : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : : * GNU General Public License for more details.
15 : : *
16 : : * You should have received a copy of the GNU General Public License
17 : : * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 : : * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 : : * Floor, Boston, MA 02110-1301, USA
20 : : *
21 : : */
22 : :
23 : : #include "internal.h"
24 : :
25 : : /* Get prototypes. */
26 : : #include "cfg.h"
27 : :
28 : : #include "low-crypto.h"
29 : :
30 : : enum
31 : : {
32 : : DEFAULT_REALM_OPTION = 0,
33 : : DEFAULT_PRINCIPAL_OPTION,
34 : : CLIENT_KDC_ETYPES_OPTION,
35 : : REALM_KDC_OPTION,
36 : : SERVER_REALM_OPTION,
37 : : KDC_TIMEOUT_OPTION,
38 : : KDC_RETRIES_OPTION,
39 : : TICKET_LIFE_OPTION,
40 : : RENEW_LIFE_OPTION,
41 : : AUTHORIZATION_TYPES_OPTION,
42 : : VERBOSE_CRYPTO_NOISE_OPTION,
43 : : VERBOSE_CRYPTO_OPTION,
44 : : VERBOSE_ASN1_OPTION,
45 : : VERBOSE_NOISE_OPTION,
46 : : VERBOSE_OPTION,
47 : : STRINGPROCESS_OPTION,
48 : : QUICK_RANDOM,
49 : : THE_END
50 : : };
51 : :
52 : : static const char *const _shishi_opts[] = {
53 : : /* [DEFAULT_REALM_OPTION] = */ "default-realm",
54 : : /* [DEFAULT_PRINCIPAL_OPTION] = */ "default-principal",
55 : : /* [CLIENT_KDC_ETYPES_OPTION] = */ "client-kdc-etypes",
56 : : /* [REALM_KDC_OPTION] = */ "realm-kdc",
57 : : /* [SERVER_REALM_OPTION] = */ "server-realm",
58 : : /* [KDC_TIMEOUT_OPTION] = */ "kdc-timeout",
59 : : /* [KDC_RETRIES_OPTION] = */ "kdc-retries",
60 : : /* [TICKET_LIFE_OPTION] = */ "ticket-life",
61 : : /* [RENEW_LIFE_OPTION] = */ "renew-life",
62 : : /* [AUTHORIZATION_TYPES_OPTION] = */ "authorization-types",
63 : : /* [VERBOSE_CRYPTO_NOISE_OPTION] = */ "verbose-crypto-noise",
64 : : /* [VERBOSE_CRYPTO_OPTION] = */ "verbose-crypto",
65 : : /* [VERBOSE_ASN1_OPTION] = */ "verbose-asn1",
66 : : /* [VERBOSE_NOISE_OPTION] = */ "verbose-noise",
67 : : /* [VERBOSE_OPTION] = */ "verbose",
68 : : /* [STRINGPROCESS_OPTION] = */ "stringprocess",
69 : : /* [QUICK_RANDOM] = */ "quick-random",
70 : : /* [THE_END] = */ NULL
71 : : };
72 : :
73 : : struct Shishi_realminfo *
74 : 0 : _shishi_realminfo (Shishi * handle, const char *realm)
75 : : {
76 : : size_t i;
77 : :
78 [ # # ]: 0 : for (i = 0; i < handle->nrealminfos; i++)
79 [ # # ]: 0 : if (strcmp (realm, handle->realminfos[i].name) == 0)
80 : 0 : return &handle->realminfos[i];
81 : :
82 : 0 : return NULL;
83 : : }
84 : :
85 : : struct Shishi_realminfo *
86 : 0 : _shishi_realminfo_new (Shishi * handle, char *realm)
87 : : {
88 : : struct Shishi_realminfo *ri;
89 : :
90 : 0 : ri = _shishi_realminfo (handle, realm);
91 [ # # ]: 0 : if (ri)
92 : 0 : return ri;
93 : :
94 : 0 : handle->realminfos = xrealloc (handle->realminfos,
95 : 0 : (++handle->nrealminfos) *
96 : : sizeof (*handle->realminfos));
97 : :
98 : 0 : ri = &handle->realminfos[handle->nrealminfos - 1];
99 : 0 : memset (ri, 0, sizeof (*ri));
100 : 0 : ri->name = realm;
101 : :
102 : 0 : return ri;
103 : : }
104 : :
105 : : /**
106 : : * shishi_cfg:
107 : : * @handle: Shishi library handle create by shishi_init().
108 : : * @option: string with shishi library option.
109 : : *
110 : : * Configure shishi library with given option.
111 : : *
112 : : * Return Value: Returns SHISHI_OK if option was valid.
113 : : **/
114 : : int
115 : 0 : shishi_cfg (Shishi * handle, const char *option)
116 : : {
117 [ # # ]: 0 : char *opt = option ? xstrdup (option) : NULL;
118 : 0 : char *p = opt;
119 : : char *value;
120 : 0 : char *realm = NULL;
121 : : int res;
122 : : size_t i;
123 : :
124 [ # # ][ # # ]: 0 : while (p != NULL && *p != '\0')
125 : : {
126 [ # # # # # : 0 : switch (getsubopt (&p, (char *const *) _shishi_opts, &value))
# # # # #
# # # # #
# # # # ]
127 : : {
128 : : case KDC_TIMEOUT_OPTION:
129 [ # # ][ # # ]: 0 : if (value && atoi (value) > 0)
130 : 0 : handle->kdctimeout = atoi (value);
131 [ # # ]: 0 : else if (value)
132 : 0 : shishi_warn (handle, "Invalid KDC timeout value: `%s'", value);
133 : : else
134 : 0 : shishi_warn (handle, "Missing KDC timeout value");
135 : 0 : break;
136 : :
137 : : case KDC_RETRIES_OPTION:
138 [ # # ][ # # ]: 0 : if (value && atoi (value) > 0)
139 : 0 : handle->kdcretries = atoi (value);
140 [ # # ]: 0 : else if (value)
141 : 0 : shishi_warn (handle, "Invalid KDC retries value: `%s'", value);
142 : : else
143 : 0 : shishi_warn (handle, "Missing KDC retries value");
144 : 0 : break;
145 : :
146 : : case TICKET_LIFE_OPTION:
147 : : {
148 : 0 : time_t now = time (NULL);
149 : 0 : time_t then = shishi_get_date (value, &now);
150 : 0 : int diff = difftime (then, now);
151 : :
152 [ # # # # ]: 0 : if (value && then != -1 && diff > 0)
[ # # ]
153 : 0 : handle->ticketlife = diff;
154 [ # # ][ # # ]: 0 : else if (diff <= 0 && diff + 60 * 60 * 24 > 0)
155 : : /* Hack to support "17:00" as always meaning the next 17:00. */
156 : 0 : handle->ticketlife = 60 * 60 * 24 + diff;
157 [ # # ]: 0 : else if (diff <= 0)
158 : 0 : shishi_warn (handle, "Negative ticket life date: `%s'", value);
159 [ # # ]: 0 : else if (then == -1)
160 : 0 : shishi_warn (handle, "Invalid ticket life date: `%s'", value);
161 : : else
162 : 0 : shishi_warn (handle, "Missing ticket life value");
163 : : }
164 : 0 : break;
165 : :
166 : : case RENEW_LIFE_OPTION:
167 : : {
168 : 0 : time_t now = time (NULL);
169 : 0 : time_t then = shishi_get_date (value, &now);
170 : 0 : int diff = difftime (then, now);
171 : :
172 [ # # # # ]: 0 : if (value && then != -1 && diff > 0)
[ # # ]
173 : 0 : handle->renewlife = diff;
174 [ # # ]: 0 : else if (diff <= 0)
175 : 0 : shishi_warn (handle, "Negative renew life date: `%s'", value);
176 [ # # ]: 0 : else if (then == -1)
177 : 0 : shishi_warn (handle, "Invalid renew life date: `%s'", value);
178 : : else
179 : 0 : shishi_warn (handle, "Missing renew life value");
180 : : }
181 : 0 : break;
182 : :
183 : : case REALM_KDC_OPTION:
184 : : {
185 : 0 : int add_realm = 1;
186 : :
187 : 0 : realm = xstrdup (value);
188 [ # # ]: 0 : for (i = 0; i < handle->nrealminfos; i++)
189 [ # # ]: 0 : if (strcmp (realm, handle->realminfos[i].name) == 0)
190 : : {
191 [ # # ][ # # ]: 0 : if (handle->realminfos[i].nkdcaddresses > 0 ||
192 : 0 : handle->realminfos[i].kdcaddresses)
193 : : {
194 : 0 : free (handle->realminfos[i].kdcaddresses);
195 : 0 : handle->realminfos[i].kdcaddresses = NULL;
196 : 0 : handle->realminfos[i].nkdcaddresses = 0;
197 : 0 : add_realm = 0;
198 : : }
199 : 0 : break;
200 : : }
201 [ # # ]: 0 : if (add_realm)
202 : : {
203 : 0 : handle->realminfos = xrealloc (handle->realminfos,
204 : : (handle->nrealminfos + 1) *
205 : : sizeof (*handle->realminfos));
206 : 0 : memset (&handle->realminfos[handle->nrealminfos], 0,
207 : : sizeof (handle->realminfos[handle->nrealminfos]));
208 : 0 : handle->realminfos[handle->nrealminfos].name = realm;
209 : 0 : handle->nrealminfos++;
210 : : }
211 : : }
212 : 0 : break;
213 : :
214 : : case SERVER_REALM_OPTION:
215 : : {
216 : : struct Shishi_realminfo *ri;
217 : 0 : ri = _shishi_realminfo_new (handle, value);
218 : 0 : ri->serverwildcards = xrealloc (ri->serverwildcards,
219 : 0 : ++ri->nserverwildcards *
220 : : sizeof (*ri->serverwildcards));
221 : 0 : ri->serverwildcards[ri->nserverwildcards - 1] = xstrdup (value);
222 : : }
223 : 0 : break;
224 : :
225 : : case DEFAULT_REALM_OPTION:
226 : 0 : handle->default_realm = xstrdup (value);
227 : 0 : break;
228 : :
229 : : case DEFAULT_PRINCIPAL_OPTION:
230 : 0 : handle->default_principal = xstrdup (value);
231 : 0 : break;
232 : :
233 : : case CLIENT_KDC_ETYPES_OPTION:
234 : 0 : res = shishi_cfg_clientkdcetype_set (handle, value);
235 [ # # ]: 0 : if (res != SHISHI_OK)
236 : 0 : goto out;
237 : 0 : break;
238 : :
239 : : case AUTHORIZATION_TYPES_OPTION:
240 : 0 : res = shishi_cfg_authorizationtype_set (handle, value);
241 [ # # ]: 0 : if (res != SHISHI_OK)
242 : 0 : goto out;
243 : 0 : break;
244 : :
245 : : case STRINGPROCESS_OPTION:
246 : 0 : free (handle->stringprocess);
247 : 0 : handle->stringprocess = xstrdup (value);
248 : 0 : break;
249 : :
250 : : case QUICK_RANDOM:
251 : 0 : _shishi_quick_random ();
252 : 0 : break;
253 : :
254 : : case VERBOSE_OPTION:
255 [ # # ][ # # ]: 0 : handle->verbose = value && atoi (value) ? atoi (value) :
256 : : ~0 & ~VERBOSES;
257 : 0 : break;
258 : :
259 : : case VERBOSE_CRYPTO_NOISE_OPTION:
260 : 0 : handle->verbose |= SHISHI_VERBOSE_CRYPTO_NOISE;
261 : 0 : break;
262 : :
263 : : case VERBOSE_CRYPTO_OPTION:
264 : 0 : handle->verbose |= SHISHI_VERBOSE_CRYPTO;
265 : 0 : break;
266 : :
267 : : case VERBOSE_ASN1_OPTION:
268 : 0 : handle->verbose |= SHISHI_VERBOSE_ASN1;
269 : 0 : break;
270 : :
271 : : case VERBOSE_NOISE_OPTION:
272 : 0 : handle->verbose |= SHISHI_VERBOSE_NOISE;
273 : 0 : break;
274 : :
275 : : case -1:
276 [ # # ]: 0 : if (!value)
277 : 0 : break;
278 [ # # ]: 0 : for (i = 0; i < handle->nrealminfos; i++)
279 [ # # ][ # # ]: 0 : if (realm && strcmp (handle->realminfos[i].name, realm) == 0)
280 : : {
281 : 0 : struct Shishi_realminfo *ri = &handle->realminfos[i];
282 : : char *protstr;
283 : 0 : int transport = UDP;
284 : :
285 [ # # ]: 0 : if ((protstr = strchr (value, '/')))
286 : : {
287 : 0 : *protstr = '\0';
288 : 0 : protstr++;
289 [ # # ]: 0 : if (strcasecmp (protstr, "udp") == 0)
290 : 0 : transport = UDP;
291 [ # # ]: 0 : else if (strcasecmp (protstr, "tcp") == 0)
292 : 0 : transport = TCP;
293 [ # # ]: 0 : else if (strcasecmp (protstr, "tls") == 0)
294 : 0 : transport = TLS;
295 : : else
296 : 0 : shishi_warn (handle,
297 : : "Ignoring unknown KDC transport: %s",
298 : : protstr);
299 : : }
300 : :
301 : 0 : ri->kdcaddresses = xrealloc (ri->kdcaddresses,
302 : : (ri->nkdcaddresses + 1) *
303 : : sizeof (*ri->kdcaddresses));
304 : 0 : ri->kdcaddresses[ri->nkdcaddresses].transport = transport;
305 : 0 : ri->kdcaddresses[ri->nkdcaddresses].hostname =
306 : 0 : xstrdup (value);
307 [ # # ]: 0 : if ((protstr = strchr (value, ':')))
308 : : {
309 : 0 : *protstr = '\0';
310 : 0 : protstr++;
311 : 0 : ri->kdcaddresses[ri->nkdcaddresses].port = protstr;
312 : : }
313 : : else
314 : 0 : ri->kdcaddresses[ri->nkdcaddresses].port = NULL;
315 : 0 : ri->nkdcaddresses++;
316 : : }
317 [ # # ]: 0 : if (realm)
318 : 0 : break;
319 : : /* fall through */
320 : :
321 : : default:
322 : 0 : shishi_warn (handle, "Unknown option: `%s'", value);
323 : : break;
324 : : }
325 : : }
326 : :
327 : 0 : res = SHISHI_OK;
328 : :
329 : : out:
330 : 0 : free (opt);
331 : 0 : return res;
332 : : }
333 : :
334 : : /**
335 : : * shishi_cfg_from_file:
336 : : * @handle: Shishi library handle create by shishi_init().
337 : : * @cfg: filename to read configuration from.
338 : : *
339 : : * Configure shishi library using configuration file.
340 : : *
341 : : * Return Value: Returns %SHISHI_OK iff successful.
342 : : **/
343 : : int
344 : 0 : shishi_cfg_from_file (Shishi * handle, const char *cfg)
345 : : {
346 : 0 : char *line = NULL;
347 : 0 : size_t len = 0;
348 : : FILE *fh;
349 : :
350 [ # # ]: 0 : if (cfg == NULL)
351 : 0 : return SHISHI_OK;
352 : :
353 : 0 : fh = fopen (cfg, "r");
354 [ # # ]: 0 : if (fh == NULL)
355 : 0 : return SHISHI_FOPEN_ERROR;
356 : :
357 [ # # ]: 0 : while (!feof (fh))
358 : : {
359 : 0 : ssize_t n = getline (&line, &len, fh);
360 : 0 : char *p = line;
361 : : char *q;
362 : :
363 [ # # ]: 0 : if (n <= 0)
364 : : /* End of file or error. */
365 : 0 : break;
366 : :
367 [ # # ][ # # ]: 0 : while (strlen (p) > 0 && (p[strlen (p) - 1] == '\n' ||
[ # # ]
368 : 0 : p[strlen (p) - 1] == '\r'))
369 : 0 : p[strlen (p) - 1] = '\0';
370 : :
371 [ # # ][ # # ]: 0 : while (*p && strchr (" \t\r\n", *p))
372 : 0 : p++;
373 : :
374 [ # # ][ # # ]: 0 : if (*p == '\0' || *p == '#')
375 : 0 : continue;
376 : :
377 : 0 : q = strchr (p, ' ');
378 [ # # ][ # # ]: 0 : if (q && (strchr (p, '=') == NULL || q < strchr (p, '=')))
[ # # ]
379 : 0 : *q = '=';
380 : :
381 : 0 : shishi_cfg (handle, p);
382 : : }
383 : :
384 : 0 : free (line);
385 : :
386 [ # # ]: 0 : if (ferror (fh))
387 : 0 : shishi_error_printf (handle, "Error reading configuration file");
388 : :
389 [ # # ]: 0 : if (fclose (fh) != 0)
390 : 0 : return SHISHI_IO_ERROR;
391 : :
392 : 0 : return SHISHI_OK;
393 : : }
394 : :
395 : : const char *
396 : 0 : _shishi_transport2string (int transport)
397 : : {
398 [ # # ]: 0 : if (transport == UDP)
399 : 0 : return "UDP";
400 [ # # ]: 0 : else if (transport == TCP)
401 : 0 : return "TCP";
402 [ # # ]: 0 : else if (transport == TLS)
403 : 0 : return "TLS";
404 : : else
405 : 0 : return "UNKNOWN";
406 : : }
407 : :
408 : : /**
409 : : * shishi_cfg_print:
410 : : * @handle: Shishi library handle create by shishi_init().
411 : : * @fh: file descriptor opened for writing.
412 : : *
413 : : * Print library configuration status, mostly for debugging purposes.
414 : : *
415 : : * Return Value: Returns SHISHI_OK.
416 : : **/
417 : : int
418 : 0 : shishi_cfg_print (Shishi * handle, FILE * fh)
419 : : {
420 : : size_t i, j;
421 : 0 : time_t tmp, now = time (NULL);
422 : :
423 : 0 : fprintf (fh, "Shishi initial library configuration:\n");
424 [ # # ]: 0 : fprintf (fh, "\tDefault realm: %s\n",
425 : 0 : handle->default_realm ? handle->default_realm : "(NULL)");
426 [ # # ]: 0 : fprintf (fh, "\tDefault principal: %s\n",
427 : 0 : handle->default_principal ? handle->default_principal : "(NULL)");
428 : 0 : fprintf (fh, "\tClient KDC etypes:");
429 [ # # ]: 0 : for (i = 0; i < handle->nclientkdcetypes; i++)
430 : 0 : fprintf (fh, " %s", shishi_cipher_name (handle->clientkdcetypes[i]));
431 : 0 : fprintf (fh, "\n");
432 : 0 : fprintf (fh, "\tVerbose: %d\n", handle->verbose);
433 : 0 : tmp = now + handle->ticketlife;
434 : 0 : fprintf (fh, "\tTicket life: %d seconds. %s",
435 : : handle->ticketlife, ctime (&tmp));
436 : 0 : tmp = now + handle->renewlife;
437 : 0 : fprintf (fh, "\tRenew life: %d seconds. %s",
438 : : handle->renewlife, ctime (&tmp));
439 [ # # ]: 0 : for (i = 0; i < handle->nrealminfos; i++)
440 : : {
441 : 0 : fprintf (fh, "\tKDCs for realm %s:\n", handle->realminfos[i].name);
442 [ # # ]: 0 : for (j = 0; j < handle->realminfos[i].nkdcaddresses; j++)
443 : 0 : fprintf (fh, "\t\tTransport %s host %s port %s\n",
444 : 0 : _shishi_transport2string (handle->realminfos[i].
445 : 0 : kdcaddresses[j].transport),
446 : 0 : handle->realminfos[i].kdcaddresses[j].hostname,
447 : 0 : handle->realminfos[i].kdcaddresses[j].port);
448 : : }
449 : :
450 : 0 : return SHISHI_OK;
451 : : }
452 : :
453 : : /**
454 : : * shishi_cfg_default_systemfile:
455 : : * @handle: Shishi library handle create by shishi_init().
456 : : *
457 : : * The system configuration file name is decided at compile-time, but
458 : : * may be overridden by the environment variable SHISHI_CONFIG.
459 : : *
460 : : * Return value: Return system configuration file name.
461 : : **/
462 : : const char *
463 : 0 : shishi_cfg_default_systemfile (Shishi * handle)
464 : : {
465 : : char *file;
466 : :
467 : 0 : file = getenv ("SHISHI_CONFIG");
468 [ # # ]: 0 : if (file)
469 : 0 : return file;
470 : :
471 : 0 : return SYSTEMCFGFILE;
472 : : }
473 : :
474 : : #define BASE_DIR "/.shishi"
475 : :
476 : : /**
477 : : * shishi_cfg_default_userdirectory:
478 : : * @handle: Shishi library handle create by shishi_init().
479 : : *
480 : : * The default user directory (used for, e.g. Shishi ticket cache) is
481 : : * normally computed by appending BASE_DIR ("/.shishi") to the content
482 : : * of the environment variable $HOME, but can be overridden by
483 : : * specifying the complete path in the environment variable
484 : : * SHISHI_HOME.
485 : : *
486 : : * Return value: Return directory with configuration files etc.
487 : : **/
488 : : const char *
489 : 2 : shishi_cfg_default_userdirectory (Shishi * handle)
490 : : {
491 : : char *home;
492 : : char *envdir;
493 : :
494 : 2 : envdir = getenv ("SHISHI_HOME");
495 [ - + ]: 2 : if (envdir)
496 : 0 : return envdir;
497 : :
498 [ + + ]: 2 : if (!handle->userdirectory)
499 : : {
500 : 1 : home = getenv ("HOME");
501 : :
502 [ + - ]: 1 : asprintf (&handle->userdirectory, "%s%s", home ? home : "", BASE_DIR);
503 : : }
504 : :
505 : 2 : return handle->userdirectory;
506 : : }
507 : :
508 : : /**
509 : : * shishi_cfg_userdirectory_file:
510 : : * @handle: Shishi library handle create by shishi_init().
511 : : * @file: basename of file to find in user directory.
512 : : *
513 : : * Get the full path to specified @file in the users' configuration
514 : : * directory.
515 : : *
516 : : * Return value: Return full path to given relative filename, relative
517 : : * to the user specific Shishi configuration directory as returned
518 : : * by shishi_cfg_default_userdirectory() (typically $HOME/.shishi).
519 : : **/
520 : : char *
521 : 2 : shishi_cfg_userdirectory_file (Shishi * handle, const char *file)
522 : : {
523 : : char *out;
524 : :
525 : 2 : asprintf (&out, "%s/%s", shishi_cfg_default_userdirectory (handle), file);
526 : :
527 : 2 : return out;
528 : : }
529 : :
530 : : #define USERCFG_FILE "shishi.conf"
531 : :
532 : : /**
533 : : * shishi_cfg_default_userfile:
534 : : * @handle: Shishi library handle create by shishi_init().
535 : : *
536 : : * Get filename of default user configuration file, typically
537 : : * $HOME/shishi.conf.
538 : : *
539 : : * Return value: Return user configuration filename.
540 : : **/
541 : : const char *
542 : 0 : shishi_cfg_default_userfile (Shishi * handle)
543 : : {
544 [ # # ]: 0 : if (!handle->usercfgfile)
545 : 0 : handle->usercfgfile =
546 : 0 : shishi_cfg_userdirectory_file (handle, USERCFG_FILE);
547 : :
548 : 0 : return handle->usercfgfile;
549 : : }
550 : :
551 : : /**
552 : : * shishi_cfg_clientkdcetype:
553 : : * @handle: Shishi library handle create by shishi_init().
554 : : * @etypes: output array with encryption types.
555 : : *
556 : : * Set the etypes variable to the array of preferred client etypes.
557 : : *
558 : : * Return value: Return the number of encryption types in the array,
559 : : * 0 means none.
560 : : **/
561 : : int
562 : 0 : shishi_cfg_clientkdcetype (Shishi * handle, int32_t ** etypes)
563 : : {
564 : 0 : *etypes = handle->clientkdcetypes;
565 : 0 : return handle->nclientkdcetypes;
566 : : }
567 : :
568 : : /**
569 : : * shishi_cfg_clientkdcetype_fast:
570 : : * @handle: Shishi library handle create by shishi_init().
571 : : *
572 : : * Extract the default etype from the list of preferred client etypes.
573 : : *
574 : : * Return value: Return the default encryption types.
575 : : **/
576 : : int32_t
577 : 0 : shishi_cfg_clientkdcetype_fast (Shishi * handle)
578 : : {
579 [ # # ]: 0 : if (handle->nclientkdcetypes > 0)
580 : 0 : return handle->clientkdcetypes[0];
581 : : else
582 : 0 : return SHISHI_AES256_CTS_HMAC_SHA1_96;
583 : : }
584 : :
585 : : /**
586 : : * shishi_cfg_clientkdcetype_set:
587 : : * @handle: Shishi library handle create by shishi_init().
588 : : * @value: string with encryption types.
589 : : *
590 : : * Set the "client-kdc-etypes" configuration option from given string.
591 : : * The string contains encryption types (integer or names) separated
592 : : * by comma or whitespace, e.g. "aes256-cts-hmac-sha1-96
593 : : * des3-cbc-sha1-kd des-cbc-md5".
594 : : *
595 : : * Return value: Return SHISHI_OK iff successful.
596 : : **/
597 : : int
598 : 0 : shishi_cfg_clientkdcetype_set (Shishi * handle, char *value)
599 : : {
600 : : char *ptrptr;
601 : : char *val;
602 : : int i;
603 : 0 : int tot = 0;
604 : :
605 [ # # ][ # # ]: 0 : if (value == NULL || *value == '\0')
606 : 0 : return SHISHI_OK;
607 : :
608 [ # # ][ # # ]: 0 : for (i = 0; (val = strtok_r (i == 0 ? value : NULL, ", \t", &ptrptr)); i++)
609 : : {
610 : 0 : int etype = shishi_cipher_parse (val);
611 : :
612 [ # # ]: 0 : if (etype == -1)
613 : 0 : shishi_warn (handle, "Ignoring unknown encryption type: `%s'", val);
614 : : else
615 : : {
616 : : int *new;
617 : :
618 : 0 : tot++;
619 : 0 : new = xrealloc (handle->clientkdcetypes,
620 : : tot * sizeof (*handle->clientkdcetypes));
621 : 0 : handle->clientkdcetypes = new;
622 : 0 : handle->clientkdcetypes[tot - 1] = etype;
623 : 0 : handle->nclientkdcetypes = tot;
624 : : }
625 : : }
626 : :
627 : 0 : return SHISHI_OK;
628 : : }
629 : :
630 : : /**
631 : : * shishi_cfg_authorizationtype_set:
632 : : * @handle: Shishi library handle create by shishi_init().
633 : : * @value: string with authorization types.
634 : : *
635 : : * Set the "authorization-types" configuration option from given string.
636 : : * The string contains authorization types (integer or names) separated
637 : : * by comma or whitespace, e.g. "basic k5login".
638 : : *
639 : : * Return value: Return SHISHI_OK iff successful.
640 : : **/
641 : : int
642 : 0 : shishi_cfg_authorizationtype_set (Shishi * handle, char *value)
643 : : {
644 : : char *ptrptr;
645 : : char *val;
646 : : int i;
647 : 0 : int tot = 0;
648 : :
649 [ # # ][ # # ]: 0 : if (value == NULL || *value == '\0')
650 : 0 : return SHISHI_OK;
651 : :
652 [ # # ][ # # ]: 0 : for (i = 0; (val = strtok_r (i == 0 ? value : NULL, ", \t", &ptrptr)); i++)
653 : : {
654 : 0 : int atype = shishi_authorization_parse (val);
655 : :
656 [ # # ]: 0 : if (atype == -1)
657 : 0 : shishi_warn (handle, "Ignoring unknown authorization type: `%s'",
658 : : val);
659 : : else
660 : : {
661 : : int *new;
662 : :
663 : 0 : tot++;
664 : 0 : new = xrealloc (handle->authorizationtypes,
665 : : tot * sizeof (*handle->authorizationtypes));
666 : 0 : handle->authorizationtypes = new;
667 : 0 : handle->authorizationtypes[tot - 1] = atype;
668 : 0 : handle->nauthorizationtypes = tot;
669 : : }
670 : : }
671 : :
672 : 0 : return SHISHI_OK;
673 : : }
|