Path: blob/main/crypto/heimdal/lib/gssapi/ntlm/iter_cred.c
34914 views
/*1* Copyright (c) 2006 Kungliga Tekniska H�gskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2009 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "ntlm.h"3637void GSSAPI_CALLCONV38_gss_ntlm_iter_creds_f(OM_uint32 flags,39void *userctx ,40void (*cred_iter)(void *, gss_OID, gss_cred_id_t))41{42#ifdef HAVE_KCM43krb5_error_code ret;44krb5_context context = NULL;45krb5_storage *request, *response;46krb5_data response_data;4748ret = krb5_init_context(&context);49if (ret)50goto done;5152ret = krb5_kcm_storage_request(context, KCM_OP_GET_NTLM_USER_LIST, &request);53if (ret)54goto done;5556ret = krb5_kcm_call(context, request, &response, &response_data);57krb5_storage_free(request);58if (ret)59goto done;6061while (1) {62uint32_t morep;63char *user = NULL, *domain = NULL;64ntlm_cred dn;6566ret = krb5_ret_uint32(response, &morep);67if (ret) goto out;6869if (!morep) goto out;7071ret = krb5_ret_stringz(response, &user);72if (ret) goto out;73ret = krb5_ret_stringz(response, &domain);74if (ret) {75free(user);76goto out;77}7879dn = calloc(1, sizeof(*dn));80if (dn == NULL) {81free(user);82free(domain);83goto out;84}85dn->username = user;86dn->domain = domain;8788cred_iter(userctx, GSS_NTLM_MECHANISM, (gss_cred_id_t)dn);89}90out:91krb5_storage_free(response);92krb5_data_free(&response_data);93done:94if (context)95krb5_free_context(context);96#endif /* HAVE_KCM */97(*cred_iter)(userctx, NULL, NULL);98}99100101