15e9cd1aeSAssar Westerlund /*
2*ae771770SStanislav Sedov * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan
35e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden).
45e9cd1aeSAssar Westerlund * All rights reserved.
55e9cd1aeSAssar Westerlund *
65e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without
75e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions
85e9cd1aeSAssar Westerlund * are met:
95e9cd1aeSAssar Westerlund *
105e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright
115e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer.
125e9cd1aeSAssar Westerlund *
135e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright
145e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the
155e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution.
165e9cd1aeSAssar Westerlund *
175e9cd1aeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors
185e9cd1aeSAssar Westerlund * may be used to endorse or promote products derived from this software
195e9cd1aeSAssar Westerlund * without specific prior written permission.
205e9cd1aeSAssar Westerlund *
215e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
225e9cd1aeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245e9cd1aeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
255e9cd1aeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
265e9cd1aeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
275e9cd1aeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285e9cd1aeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
295e9cd1aeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
305e9cd1aeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315e9cd1aeSAssar Westerlund * SUCH DAMAGE.
325e9cd1aeSAssar Westerlund */
335e9cd1aeSAssar Westerlund
345e9cd1aeSAssar Westerlund #include "kadm5_locl.h"
355e9cd1aeSAssar Westerlund
36*ae771770SStanislav Sedov RCSID("$Id$");
375e9cd1aeSAssar Westerlund
385e9cd1aeSAssar Westerlund /*
395e9cd1aeSAssar Westerlund * free all the memory used by (len, keys)
405e9cd1aeSAssar Westerlund */
415e9cd1aeSAssar Westerlund
425e9cd1aeSAssar Westerlund void
_kadm5_free_keys(krb5_context context,int len,Key * keys)43c19800e8SDoug Rabson _kadm5_free_keys (krb5_context context,
445e9cd1aeSAssar Westerlund int len, Key *keys)
455e9cd1aeSAssar Westerlund {
46c19800e8SDoug Rabson hdb_free_keys(context, len, keys);
475e9cd1aeSAssar Westerlund }
485e9cd1aeSAssar Westerlund
495e9cd1aeSAssar Westerlund /*
505e9cd1aeSAssar Westerlund * null-ify `len', `keys'
515e9cd1aeSAssar Westerlund */
525e9cd1aeSAssar Westerlund
535e9cd1aeSAssar Westerlund void
_kadm5_init_keys(Key * keys,int len)545e9cd1aeSAssar Westerlund _kadm5_init_keys (Key *keys, int len)
555e9cd1aeSAssar Westerlund {
565e9cd1aeSAssar Westerlund int i;
575e9cd1aeSAssar Westerlund
585e9cd1aeSAssar Westerlund for (i = 0; i < len; ++i) {
595e9cd1aeSAssar Westerlund keys[i].mkvno = NULL;
605e9cd1aeSAssar Westerlund keys[i].salt = NULL;
615e9cd1aeSAssar Westerlund keys[i].key.keyvalue.length = 0;
625e9cd1aeSAssar Westerlund keys[i].key.keyvalue.data = NULL;
635e9cd1aeSAssar Westerlund }
645e9cd1aeSAssar Westerlund }
655e9cd1aeSAssar Westerlund
665e9cd1aeSAssar Westerlund /*
67*ae771770SStanislav Sedov * return 1 if any key in `keys1, len1' exists in `keys2, len2'
685e9cd1aeSAssar Westerlund */
695e9cd1aeSAssar Westerlund
705e9cd1aeSAssar Westerlund int
_kadm5_exists_keys(Key * keys1,int len1,Key * keys2,int len2)71*ae771770SStanislav Sedov _kadm5_exists_keys(Key *keys1, int len1, Key *keys2, int len2)
725e9cd1aeSAssar Westerlund {
73*ae771770SStanislav Sedov int i, j;
745e9cd1aeSAssar Westerlund
755e9cd1aeSAssar Westerlund for (i = 0; i < len1; ++i) {
76*ae771770SStanislav Sedov for (j = 0; j < len2; j++) {
77*ae771770SStanislav Sedov if ((keys1[i].salt != NULL && keys2[j].salt == NULL)
78*ae771770SStanislav Sedov || (keys1[i].salt == NULL && keys2[j].salt != NULL))
79*ae771770SStanislav Sedov continue;
80*ae771770SStanislav Sedov
815e9cd1aeSAssar Westerlund if (keys1[i].salt != NULL) {
82*ae771770SStanislav Sedov if (keys1[i].salt->type != keys2[j].salt->type)
83*ae771770SStanislav Sedov continue;
84*ae771770SStanislav Sedov if (keys1[i].salt->salt.length != keys2[j].salt->salt.length)
85*ae771770SStanislav Sedov continue;
86*ae771770SStanislav Sedov if (memcmp (keys1[i].salt->salt.data, keys2[j].salt->salt.data,
875e9cd1aeSAssar Westerlund keys1[i].salt->salt.length) != 0)
88*ae771770SStanislav Sedov continue;
89*ae771770SStanislav Sedov }
90*ae771770SStanislav Sedov if (keys1[i].key.keytype != keys2[j].key.keytype)
91*ae771770SStanislav Sedov continue;
92*ae771770SStanislav Sedov if (keys1[i].key.keyvalue.length != keys2[j].key.keyvalue.length)
93*ae771770SStanislav Sedov continue;
94*ae771770SStanislav Sedov if (memcmp (keys1[i].key.keyvalue.data, keys2[j].key.keyvalue.data,
95*ae771770SStanislav Sedov keys1[i].key.keyvalue.length) != 0)
96*ae771770SStanislav Sedov continue;
97*ae771770SStanislav Sedov
985e9cd1aeSAssar Westerlund return 1;
995e9cd1aeSAssar Westerlund }
1005e9cd1aeSAssar Westerlund }
1015e9cd1aeSAssar Westerlund return 0;
1025e9cd1aeSAssar Westerlund }
103