1 /* $NetBSD: gss_acquire_cred_with_password.c,v 1.2 2017/01/28 21:31:46 christos Exp $ */ 2 3 /* 4 * Copyright (c) 2011, PADL Software Pty Ltd. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * 3. Neither the name of PADL Software nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY PADL SOFTWARE AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL PADL SOFTWARE OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #include "mech_locl.h" 36 37 GSSAPI_LIB_FUNCTION OM_uint32 GSSAPI_LIB_CALL 38 gss_acquire_cred_with_password(OM_uint32 *minor_status, 39 gss_const_name_t desired_name, 40 const gss_buffer_t password, 41 OM_uint32 time_req, 42 const gss_OID_set desired_mechs, 43 gss_cred_usage_t cred_usage, 44 gss_cred_id_t *output_cred_handle, 45 gss_OID_set *actual_mechs, 46 OM_uint32 *time_rec) 47 { 48 OM_uint32 major_status, tmp_minor; 49 50 if (desired_mechs == GSS_C_NO_OID_SET) { 51 major_status = _gss_acquire_cred_ext(minor_status, 52 desired_name, 53 GSS_C_CRED_PASSWORD, 54 password, 55 time_req, 56 GSS_C_NO_OID, 57 cred_usage, 58 output_cred_handle); 59 if (GSS_ERROR(major_status)) 60 return major_status; 61 } else { 62 size_t i; 63 struct _gss_cred *new_cred; 64 65 new_cred = calloc(1, sizeof(*new_cred)); 66 if (new_cred == NULL) { 67 *minor_status = ENOMEM; 68 return GSS_S_FAILURE; 69 } 70 HEIM_SLIST_INIT(&new_cred->gc_mc); 71 72 for (i = 0; i < desired_mechs->count; i++) { 73 struct _gss_cred *tmp_cred = NULL; 74 struct _gss_mechanism_cred *mc; 75 76 major_status = _gss_acquire_cred_ext(minor_status, 77 desired_name, 78 GSS_C_CRED_PASSWORD, 79 password, 80 time_req, 81 &desired_mechs->elements[i], 82 cred_usage, 83 (gss_cred_id_t *)&tmp_cred); 84 if (GSS_ERROR(major_status)) 85 continue; 86 87 mc = HEIM_SLIST_FIRST(&tmp_cred->gc_mc); 88 if (mc) { 89 HEIM_SLIST_REMOVE_HEAD(&tmp_cred->gc_mc, gmc_link); 90 HEIM_SLIST_INSERT_HEAD(&new_cred->gc_mc, mc, gmc_link); 91 } 92 93 gss_release_cred(&tmp_minor, (gss_cred_id_t *)&tmp_cred); 94 } 95 96 if (!HEIM_SLIST_FIRST(&new_cred->gc_mc)) { 97 free(new_cred); 98 if (desired_mechs->count > 1) 99 *minor_status = 0; 100 return GSS_S_NO_CRED; 101 } 102 103 *output_cred_handle = (gss_cred_id_t)new_cred; 104 } 105 106 if (actual_mechs != NULL || time_rec != NULL) { 107 major_status = gss_inquire_cred(minor_status, 108 *output_cred_handle, 109 NULL, 110 time_rec, 111 NULL, 112 actual_mechs); 113 if (GSS_ERROR(major_status)) { 114 gss_release_cred(&tmp_minor, output_cred_handle); 115 return major_status; 116 } 117 } 118 119 *minor_status = 0; 120 return GSS_S_COMPLETE; 121 } 122