/* * lib/kadm/keysalt.c * * Copyright 1995 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may * require a specific license from the United States Government. * It is the responsibility of any person or organization contemplating * export to obtain such a license before exporting. * * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and * distribute this software and its documentation for any purpose and * without fee is hereby granted, provided that the above copyright * notice appear in all copies and that both that copyright notice and * this permission notice appear in supporting documentation, and that * the name of M.I.T. not be used in advertising or publicity pertaining * to distribution of the software without specific, written prior * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. * */ /* * keysalt.c - Routines to handle key/salt tuples. */ #include "k5-int.h" #include "adm.h" #include "adm_proto.h" static const char default_tupleseps[] = ", \t"; static const char default_ksaltseps[] = ":."; /* * krb5_keysalt_is_present() - Determine if a key/salt pair is present * in a list of key/salt tuples. * * Salttype may be negative to indicate a search for only a enctype. */ krb5_boolean krb5_keysalt_is_present(ksaltlist, nksalts, enctype, salttype) krb5_key_salt_tuple *ksaltlist; krb5_int32 nksalts; krb5_enctype enctype; krb5_int32 salttype; { krb5_boolean foundit; int i; foundit = 0; if (ksaltlist) { for (i=0; i * or * */ sp = (char *) NULL; /* Attempt to find a separator */ septmp = ksseplist; for (sp = strchr(kp, (int) *septmp); *(++septmp) && !sp; ep = strchr(kp, (int) *septmp)); if (sp) { /* Separate enctype from salttype */ sepchar = *sp; *sp = '\0'; sp++; } else stype = -1; /* * Attempt to parse enctype and salttype. If we parse well * then make sure that it specifies a unique key/salt combo */ if (!krb5_string_to_enctype(kp, &ktype) && (!sp || !krb5_string_to_salttype(sp, &stype)) && (dups || !krb5_keysalt_is_present(*ksaltp, *nksaltp, ktype, stype))) { /* Squirrel away old keysalt array */ savep = *ksaltp; len = (size_t) *nksaltp; /* Get new keysalt array */ if (*ksaltp = (krb5_key_salt_tuple *) malloc((len + 1) * sizeof(krb5_key_salt_tuple))) { /* Copy old keysalt if appropriate */ if (savep) { memcpy(*ksaltp, savep, len * sizeof(krb5_key_salt_tuple)); krb5_xfree(savep); } /* Save our values */ (*ksaltp)[(*nksaltp)].ks_enctype = ktype; (*ksaltp)[(*nksaltp)].ks_salttype = stype; (*nksaltp)++; } else { *ksaltp = savep; break; } } if (sp) sp[-1] = sepchar; if (ep) ep[-1] = trailchar; kp = ep; } return(kret); }