|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/* kdc/authind.c - Functions for manipulating authentication indicator lists */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (C) 2015 by the Massachusetts Institute of Technology.
|
|
Packit |
fd8b60 |
* All rights reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
fd8b60 |
* modification, are permitted provided that the following conditions
|
|
Packit |
fd8b60 |
* are met:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* * Redistributions of source code must retain the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* * Redistributions in binary form must reproduce the above copyright
|
|
Packit |
fd8b60 |
* notice, this list of conditions and the following disclaimer in
|
|
Packit |
fd8b60 |
* the documentation and/or other materials provided with the
|
|
Packit |
fd8b60 |
* distribution.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
Packit |
fd8b60 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
Packit |
fd8b60 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
Packit |
fd8b60 |
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
Packit |
fd8b60 |
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
Packit |
fd8b60 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
Packit |
fd8b60 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Packit |
fd8b60 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
Packit |
fd8b60 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
Packit |
fd8b60 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
fd8b60 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
Packit |
fd8b60 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#include "k5-int.h"
|
|
Packit |
fd8b60 |
#include "kdc_util.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Return true if ind matches an entry in indicators. */
|
|
Packit |
fd8b60 |
krb5_boolean
|
|
Packit |
fd8b60 |
authind_contains(krb5_data *const *indicators, const char *ind)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
for (; indicators != NULL && *indicators != NULL; indicators++) {
|
|
Packit |
fd8b60 |
if (data_eq_string(**indicators, ind))
|
|
Packit |
fd8b60 |
return TRUE;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
return FALSE;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Add ind to *indicators, reallocating as necessary. */
|
|
Packit |
fd8b60 |
krb5_error_code
|
|
Packit |
fd8b60 |
authind_add(krb5_context context, const char *ind, krb5_data ***indicators)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
size_t count;
|
|
Packit |
fd8b60 |
krb5_data **list = *indicators, *dptr, d;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Count the number of existing indicators and check for duplicates. */
|
|
Packit |
fd8b60 |
for (count = 0; list != NULL && list[count] != NULL; count++) {
|
|
Packit |
fd8b60 |
if (data_eq_string(*list[count], ind))
|
|
Packit |
fd8b60 |
return 0;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Allocate space for a new entry. */
|
|
Packit |
fd8b60 |
list = realloc(list, (count + 2) * sizeof(*list));
|
|
Packit |
fd8b60 |
if (list == NULL)
|
|
Packit |
fd8b60 |
return ENOMEM;
|
|
Packit |
fd8b60 |
*indicators = list;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Add a copy of ind (as a krb5_data object) to the list. */
|
|
Packit |
fd8b60 |
d = string2data((char *)ind);
|
|
Packit |
fd8b60 |
if (krb5_copy_data(context, &d, &dptr) != 0)
|
|
Packit |
fd8b60 |
return ENOMEM;
|
|
Packit |
fd8b60 |
list[count++] = dptr;
|
|
Packit |
fd8b60 |
list[count] = NULL;
|
|
Packit |
fd8b60 |
return 0;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Add all auth indicators from authdata to *indicators, reallocating as
|
|
Packit |
fd8b60 |
* necessary. (Currently does not compress duplicates.) */
|
|
Packit |
fd8b60 |
krb5_error_code
|
|
Packit |
fd8b60 |
authind_extract(krb5_context context, krb5_authdata **authdata,
|
|
Packit |
fd8b60 |
krb5_data ***indicators)
|
|
Packit |
fd8b60 |
{
|
|
Packit |
fd8b60 |
krb5_error_code ret;
|
|
Packit |
fd8b60 |
size_t count, scount;
|
|
Packit |
fd8b60 |
krb5_authdata **ind_authdata = NULL, **adp;
|
|
Packit |
fd8b60 |
krb5_data der_indicators, **strings = NULL, **list = *indicators;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
for (count = 0; list != NULL && list[count] != NULL; count++);
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
ret = krb5_find_authdata(context, authdata, NULL,
|
|
Packit |
fd8b60 |
KRB5_AUTHDATA_AUTH_INDICATOR, &ind_authdata);
|
|
Packit |
fd8b60 |
if (ret)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
for (adp = ind_authdata; adp != NULL && *adp != NULL; adp++) {
|
|
Packit |
fd8b60 |
/* Decode this authdata element into an auth indicator list. */
|
|
Packit |
fd8b60 |
der_indicators = make_data((*adp)->contents, (*adp)->length);
|
|
Packit |
fd8b60 |
ret = decode_utf8_strings(&der_indicators, &strings);
|
|
Packit |
fd8b60 |
if (ret == ENOMEM)
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
if (ret)
|
|
Packit |
fd8b60 |
continue;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Count the entries in strings and allocate space in list. */
|
|
Packit |
fd8b60 |
for (scount = 0; strings != NULL && strings[scount] != NULL; scount++);
|
|
Packit |
fd8b60 |
list = realloc(list, (count + scount + 1) * sizeof(*list));
|
|
Packit |
fd8b60 |
if (list == NULL) {
|
|
Packit |
fd8b60 |
ret = ENOMEM;
|
|
Packit |
fd8b60 |
goto cleanup;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
*indicators = list;
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Steal the krb5_data pointers from strings and free the array. */
|
|
Packit |
fd8b60 |
memcpy(list + count, strings, scount * sizeof(*strings));
|
|
Packit |
fd8b60 |
count += scount;
|
|
Packit |
fd8b60 |
list[count] = NULL;
|
|
Packit |
fd8b60 |
free(strings);
|
|
Packit |
fd8b60 |
strings = NULL;
|
|
Packit |
fd8b60 |
}
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
cleanup:
|
|
Packit |
fd8b60 |
krb5_free_authdata(context, ind_authdata);
|
|
Packit |
fd8b60 |
k5_free_data_ptr_list(strings);
|
|
Packit |
fd8b60 |
return ret;
|
|
Packit |
fd8b60 |
}
|