xref: /freebsd/crypto/krb5/src/lib/gssapi/krb5/cred_store.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2011 Red Hat, Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation files
7  * (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include "gssapiP_krb5.h"
27 
28 OM_uint32
kg_value_from_cred_store(gss_const_key_value_set_t cred_store,const char * type,const char ** value)29 kg_value_from_cred_store(gss_const_key_value_set_t cred_store,
30                          const char *type, const char **value)
31 {
32     OM_uint32 i;
33 
34     if (value == NULL)
35         return GSS_S_CALL_INACCESSIBLE_WRITE;
36     *value = NULL;
37 
38     if (cred_store == GSS_C_NO_CRED_STORE)
39         return GSS_S_COMPLETE;
40 
41     for (i = 0; i < cred_store->count; i++) {
42         if (strcmp(cred_store->elements[i].key, type) == 0) {
43             if (*value != NULL)
44                 return GSS_S_DUPLICATE_ELEMENT;
45             *value = cred_store->elements[i].value;
46         }
47     }
48 
49     return GSS_S_COMPLETE;
50 }
51