10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
90Sstevel@tonic-gate *
100Sstevel@tonic-gate * Openvision retains the copyright to derivative works of
110Sstevel@tonic-gate * this source code. Do *NOT* create a derivative of this
120Sstevel@tonic-gate * source code before consulting with your legal department.
130Sstevel@tonic-gate * Do *NOT* integrate *ANY* of this source code into another
140Sstevel@tonic-gate * product before consulting with your legal department.
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * For further information, read the top-level Openvision
170Sstevel@tonic-gate * copyright which is contained in the top-level MIT Kerberos
180Sstevel@tonic-gate * copyright.
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
210Sstevel@tonic-gate *
220Sstevel@tonic-gate */
230Sstevel@tonic-gate
240Sstevel@tonic-gate
250Sstevel@tonic-gate /*
260Sstevel@tonic-gate * lib/kadm/str_conv.c
270Sstevel@tonic-gate *
280Sstevel@tonic-gate * Copyright 1995 by the Massachusetts Institute of Technology.
290Sstevel@tonic-gate * All Rights Reserved.
300Sstevel@tonic-gate *
310Sstevel@tonic-gate * Export of this software from the United States of America may
320Sstevel@tonic-gate * require a specific license from the United States Government.
330Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
340Sstevel@tonic-gate * export to obtain such a license before exporting.
350Sstevel@tonic-gate *
360Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
370Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
380Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
390Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
400Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
410Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
420Sstevel@tonic-gate * to distribution of the software without specific, written prior
430Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
440Sstevel@tonic-gate * your software as modified software and not distribute it in such a
450Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
460Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
470Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
480Sstevel@tonic-gate * or implied warranty.
490Sstevel@tonic-gate *
500Sstevel@tonic-gate */
510Sstevel@tonic-gate
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate * str_conv.c - Convert between strings and Kerberos internal data.
540Sstevel@tonic-gate */
550Sstevel@tonic-gate
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate * Table of contents:
580Sstevel@tonic-gate *
590Sstevel@tonic-gate * String decoding:
600Sstevel@tonic-gate * ----------------
610Sstevel@tonic-gate * krb5_string_to_flags() - Convert string to krb5_flags.
620Sstevel@tonic-gate *
630Sstevel@tonic-gate * String encoding:
640Sstevel@tonic-gate * ----------------
650Sstevel@tonic-gate * krb5_flags_to_string() - Convert krb5_flags to string.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate
680Sstevel@tonic-gate #include "k5-int.h"
690Sstevel@tonic-gate #include "admin_internal.h"
702881Smp153739 #include "adm_proto.h"
710Sstevel@tonic-gate
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate * Local data structures.
740Sstevel@tonic-gate */
750Sstevel@tonic-gate struct flags_lookup_entry {
760Sstevel@tonic-gate krb5_flags fl_flags; /* Flag */
770Sstevel@tonic-gate krb5_boolean fl_sense; /* Sense of the flag */
780Sstevel@tonic-gate const char * fl_specifier; /* How to recognize it */
790Sstevel@tonic-gate const char * fl_output; /* How to spit it out */
800Sstevel@tonic-gate };
810Sstevel@tonic-gate
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate * Local strings
840Sstevel@tonic-gate */
850Sstevel@tonic-gate
860Sstevel@tonic-gate static const char default_tupleseps[] = ", \t";
870Sstevel@tonic-gate static const char default_ksaltseps[] = ":.";
880Sstevel@tonic-gate
890Sstevel@tonic-gate /* Keytype strings */
900Sstevel@tonic-gate /* Flags strings */
910Sstevel@tonic-gate static const char flags_pdate_in[] = "postdateable";
920Sstevel@tonic-gate static const char flags_fwd_in[] = "forwardable";
930Sstevel@tonic-gate static const char flags_tgtbased_in[] = "tgt-based";
940Sstevel@tonic-gate static const char flags_renew_in[] = "renewable";
950Sstevel@tonic-gate static const char flags_proxy_in[] = "proxiable";
960Sstevel@tonic-gate static const char flags_dup_skey_in[] = "dup-skey";
970Sstevel@tonic-gate static const char flags_tickets_in[] = "allow-tickets";
980Sstevel@tonic-gate static const char flags_preauth_in[] = "preauth";
990Sstevel@tonic-gate static const char flags_hwauth_in[] = "hwauth";
1000Sstevel@tonic-gate static const char flags_pwchange_in[] = "pwchange";
1010Sstevel@tonic-gate static const char flags_service_in[] = "service";
1020Sstevel@tonic-gate static const char flags_pwsvc_in[] = "pwservice";
1030Sstevel@tonic-gate static const char flags_md5_in[] = "md5";
1040Sstevel@tonic-gate static const char flags_pdate_out[] = "Not Postdateable";
1050Sstevel@tonic-gate static const char flags_fwd_out[] = "Not Forwardable";
1060Sstevel@tonic-gate static const char flags_tgtbased_out[] = "No TGT-based requests";
1070Sstevel@tonic-gate static const char flags_renew_out[] = "Not renewable";
1080Sstevel@tonic-gate static const char flags_proxy_out[] = "Not proxiable";
1090Sstevel@tonic-gate static const char flags_dup_skey_out[] = "No DUP_SKEY requests";
1100Sstevel@tonic-gate static const char flags_tickets_out[] = "All Tickets Disallowed";
1110Sstevel@tonic-gate static const char flags_preauth_out[] = "Preauthorization required";
1120Sstevel@tonic-gate static const char flags_hwauth_out[] = "HW Authorization required";
1130Sstevel@tonic-gate static const char flags_pwchange_out[] = "Password Change required";
1140Sstevel@tonic-gate static const char flags_service_out[] = "Service Disabled";
1150Sstevel@tonic-gate static const char flags_pwsvc_out[] = "Password Changing Service";
1160Sstevel@tonic-gate static const char flags_md5_out[] = "RSA-MD5 supported";
1170Sstevel@tonic-gate static const char flags_default_neg[] = "-";
1180Sstevel@tonic-gate static const char flags_default_sep[] = " ";
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate /*
1210Sstevel@tonic-gate * Lookup tables.
1220Sstevel@tonic-gate */
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate static const struct flags_lookup_entry flags_table[] = {
1250Sstevel@tonic-gate /* flag sense input specifier output string */
1260Sstevel@tonic-gate /*----------------------------- ------- ------------------ ------------------*/
1270Sstevel@tonic-gate { KRB5_KDB_DISALLOW_POSTDATED, 0, flags_pdate_in, flags_pdate_out },
1280Sstevel@tonic-gate { KRB5_KDB_DISALLOW_FORWARDABLE,0, flags_fwd_in, flags_fwd_out },
1290Sstevel@tonic-gate { KRB5_KDB_DISALLOW_TGT_BASED, 0, flags_tgtbased_in, flags_tgtbased_out},
1300Sstevel@tonic-gate { KRB5_KDB_DISALLOW_RENEWABLE, 0, flags_renew_in, flags_renew_out },
1310Sstevel@tonic-gate { KRB5_KDB_DISALLOW_PROXIABLE, 0, flags_proxy_in, flags_proxy_out },
1320Sstevel@tonic-gate { KRB5_KDB_DISALLOW_DUP_SKEY, 0, flags_dup_skey_in, flags_dup_skey_out},
1330Sstevel@tonic-gate { KRB5_KDB_DISALLOW_ALL_TIX, 0, flags_tickets_in, flags_tickets_out },
1340Sstevel@tonic-gate { KRB5_KDB_REQUIRES_PRE_AUTH, 1, flags_preauth_in, flags_preauth_out },
1350Sstevel@tonic-gate { KRB5_KDB_REQUIRES_HW_AUTH, 1, flags_hwauth_in, flags_hwauth_out },
1360Sstevel@tonic-gate { KRB5_KDB_REQUIRES_PWCHANGE, 1, flags_pwchange_in, flags_pwchange_out},
1370Sstevel@tonic-gate { KRB5_KDB_DISALLOW_SVR, 0, flags_service_in, flags_service_out },
1380Sstevel@tonic-gate { KRB5_KDB_PWCHANGE_SERVICE, 1, flags_pwsvc_in, flags_pwsvc_out },
1390Sstevel@tonic-gate { KRB5_KDB_SUPPORT_DESMD5, 1, flags_md5_in, flags_md5_out }
1400Sstevel@tonic-gate };
1410Sstevel@tonic-gate static const int flags_table_nents = sizeof(flags_table)/
1420Sstevel@tonic-gate sizeof(flags_table[0]);
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate krb5_error_code
krb5_string_to_flags(string,positive,negative,flagsp)1460Sstevel@tonic-gate krb5_string_to_flags(string, positive, negative, flagsp)
1470Sstevel@tonic-gate char * string;
1480Sstevel@tonic-gate const char * positive;
1490Sstevel@tonic-gate const char * negative;
1500Sstevel@tonic-gate krb5_flags * flagsp;
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate int i;
1530Sstevel@tonic-gate int found;
1540Sstevel@tonic-gate const char *neg;
1550Sstevel@tonic-gate size_t nsize, psize;
1560Sstevel@tonic-gate int cpos;
1570Sstevel@tonic-gate int sense;
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate found = 0;
1600Sstevel@tonic-gate /* We need to have a way to negate it. */
1610Sstevel@tonic-gate neg = (negative) ? negative : flags_default_neg;
1620Sstevel@tonic-gate nsize = strlen(neg);
1630Sstevel@tonic-gate psize = (positive) ? strlen(positive) : 0;
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate cpos = 0;
1660Sstevel@tonic-gate sense = 1;
1670Sstevel@tonic-gate /* First check for positive or negative sense */
1680Sstevel@tonic-gate if (!strncasecmp(neg, string, nsize)) {
1690Sstevel@tonic-gate sense = 0;
1700Sstevel@tonic-gate cpos += (int) nsize;
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate else if (psize && !strncasecmp(positive, string, psize)) {
1730Sstevel@tonic-gate cpos += (int) psize;
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate for (i=0; i<flags_table_nents; i++) {
1770Sstevel@tonic-gate if (!strcasecmp(&string[cpos], flags_table[i].fl_specifier)) {
1780Sstevel@tonic-gate found = 1;
1790Sstevel@tonic-gate if (sense == (int) flags_table[i].fl_sense)
1800Sstevel@tonic-gate *flagsp |= flags_table[i].fl_flags;
1810Sstevel@tonic-gate else
1820Sstevel@tonic-gate *flagsp &= ~flags_table[i].fl_flags;
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate break;
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate return((found) ? 0 : EINVAL);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate krb5_error_code
krb5_flags_to_string(flags,sep,buffer,buflen)1910Sstevel@tonic-gate krb5_flags_to_string(flags, sep, buffer, buflen)
1920Sstevel@tonic-gate krb5_flags flags;
1930Sstevel@tonic-gate const char * sep;
1940Sstevel@tonic-gate char * buffer;
1950Sstevel@tonic-gate size_t buflen;
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate int i;
1980Sstevel@tonic-gate krb5_flags pflags;
1990Sstevel@tonic-gate const char *sepstring;
2000Sstevel@tonic-gate char *op;
2010Sstevel@tonic-gate int initial;
2020Sstevel@tonic-gate krb5_error_code retval;
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate retval = 0;
2050Sstevel@tonic-gate op = buffer;
2060Sstevel@tonic-gate pflags = 0;
2070Sstevel@tonic-gate initial = 1;
2080Sstevel@tonic-gate sepstring = (sep) ? sep : flags_default_sep;
2090Sstevel@tonic-gate /* Blast through the table matching all we can */
2100Sstevel@tonic-gate for (i=0; i<flags_table_nents; i++) {
2110Sstevel@tonic-gate if (flags & flags_table[i].fl_flags) {
2120Sstevel@tonic-gate /* Found a match, see if it'll fit into the output buffer */
2130Sstevel@tonic-gate if ((op+strlen(flags_table[i].fl_output)+strlen(sepstring)) <
2140Sstevel@tonic-gate (buffer + buflen)) {
2150Sstevel@tonic-gate if (!initial) {
2160Sstevel@tonic-gate strcpy(op, sep);
2170Sstevel@tonic-gate op += strlen(sep);
2180Sstevel@tonic-gate }
2190Sstevel@tonic-gate initial = 0;
2200Sstevel@tonic-gate strcpy(op, flags_table[i].fl_output);
2210Sstevel@tonic-gate op += strlen(flags_table[i].fl_output);
2220Sstevel@tonic-gate }
2230Sstevel@tonic-gate else {
2240Sstevel@tonic-gate retval = ENOMEM;
2250Sstevel@tonic-gate break;
2260Sstevel@tonic-gate }
2270Sstevel@tonic-gate /* Keep track of what we matched */
2280Sstevel@tonic-gate pflags |= flags_table[i].fl_flags;
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate if (!retval) {
2320Sstevel@tonic-gate /* See if there's any leftovers */
2330Sstevel@tonic-gate if (flags & ~pflags)
2340Sstevel@tonic-gate retval = EINVAL;
2350Sstevel@tonic-gate else if (initial)
2360Sstevel@tonic-gate *buffer = '\0';
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate return(retval);
2390Sstevel@tonic-gate }
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate krb5_error_code
krb5_input_flag_to_string(flag,buffer,buflen)2420Sstevel@tonic-gate krb5_input_flag_to_string(flag, buffer, buflen)
2430Sstevel@tonic-gate int flag;
2440Sstevel@tonic-gate char * buffer;
2450Sstevel@tonic-gate size_t buflen;
2460Sstevel@tonic-gate {
2470Sstevel@tonic-gate if(flag < 0 || flag >= flags_table_nents) return ENOENT; /* End of list */
2480Sstevel@tonic-gate if(strlen(flags_table[flag].fl_specifier) > buflen) return ENOMEM;
2490Sstevel@tonic-gate strcpy(buffer, flags_table[flag].fl_specifier);
2500Sstevel@tonic-gate return 0;
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate /*
2540Sstevel@tonic-gate * krb5_keysalt_is_present() - Determine if a key/salt pair is present
2550Sstevel@tonic-gate * in a list of key/salt tuples.
2560Sstevel@tonic-gate *
2570Sstevel@tonic-gate * Salttype may be negative to indicate a search for only a enctype.
2580Sstevel@tonic-gate */
2590Sstevel@tonic-gate krb5_boolean
krb5_keysalt_is_present(ksaltlist,nksalts,enctype,salttype)2600Sstevel@tonic-gate krb5_keysalt_is_present(ksaltlist, nksalts, enctype, salttype)
2610Sstevel@tonic-gate krb5_key_salt_tuple *ksaltlist;
2620Sstevel@tonic-gate krb5_int32 nksalts;
2630Sstevel@tonic-gate krb5_enctype enctype;
2640Sstevel@tonic-gate krb5_int32 salttype;
2650Sstevel@tonic-gate {
2660Sstevel@tonic-gate krb5_boolean foundit;
2670Sstevel@tonic-gate int i;
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate foundit = 0;
2700Sstevel@tonic-gate if (ksaltlist) {
2710Sstevel@tonic-gate for (i=0; i<nksalts; i++) {
2720Sstevel@tonic-gate if ((ksaltlist[i].ks_enctype == enctype) &&
2730Sstevel@tonic-gate ((ksaltlist[i].ks_salttype == salttype) ||
2740Sstevel@tonic-gate (salttype < 0))) {
2750Sstevel@tonic-gate foundit = 1;
2760Sstevel@tonic-gate break;
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate return(foundit);
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate /*
2840Sstevel@tonic-gate * krb5_string_to_keysalts() - Convert a string representation to a list
2850Sstevel@tonic-gate * of key/salt tuples.
2860Sstevel@tonic-gate */
2870Sstevel@tonic-gate krb5_error_code
krb5_string_to_keysalts(string,tupleseps,ksaltseps,dups,ksaltp,nksaltp)2880Sstevel@tonic-gate krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp)
2890Sstevel@tonic-gate char *string;
2900Sstevel@tonic-gate const char *tupleseps;
2910Sstevel@tonic-gate const char *ksaltseps;
2920Sstevel@tonic-gate krb5_boolean dups;
2930Sstevel@tonic-gate krb5_key_salt_tuple **ksaltp;
2940Sstevel@tonic-gate krb5_int32 *nksaltp;
2950Sstevel@tonic-gate {
2960Sstevel@tonic-gate krb5_error_code kret;
2970Sstevel@tonic-gate char *kp, *sp, *ep;
2980Sstevel@tonic-gate char sepchar, trailchar;
2990Sstevel@tonic-gate krb5_enctype ktype;
3000Sstevel@tonic-gate krb5_int32 stype;
3010Sstevel@tonic-gate krb5_key_salt_tuple *savep;
3020Sstevel@tonic-gate const char *tseplist;
3030Sstevel@tonic-gate const char *ksseplist;
3040Sstevel@tonic-gate const char *septmp;
3050Sstevel@tonic-gate size_t len;
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate kret = 0;
3080Sstevel@tonic-gate kp = string;
3090Sstevel@tonic-gate tseplist = (tupleseps) ? tupleseps : default_tupleseps;
3100Sstevel@tonic-gate ksseplist = (ksaltseps) ? ksaltseps : default_ksaltseps;
3110Sstevel@tonic-gate while (kp) {
3120Sstevel@tonic-gate /* Attempt to find a separator */
3130Sstevel@tonic-gate ep = (char *) NULL;
3140Sstevel@tonic-gate if (*tseplist) {
3150Sstevel@tonic-gate septmp = tseplist;
3160Sstevel@tonic-gate for (ep = strchr(kp, (int) *septmp);
3170Sstevel@tonic-gate *(++septmp) && !ep;
3180Sstevel@tonic-gate ep = strchr(kp, (int) *septmp));
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate if (ep) {
3220Sstevel@tonic-gate trailchar = *ep;
3230Sstevel@tonic-gate *ep = '\0';
3240Sstevel@tonic-gate ep++;
3250Sstevel@tonic-gate }
3260Sstevel@tonic-gate /*
3270Sstevel@tonic-gate * kp points to something (hopefully) of the form:
3280Sstevel@tonic-gate * <enctype><ksseplist><salttype>
3290Sstevel@tonic-gate * or
3300Sstevel@tonic-gate * <enctype>
3310Sstevel@tonic-gate */
3320Sstevel@tonic-gate sp = (char *) NULL;
3330Sstevel@tonic-gate /* Attempt to find a separator */
3340Sstevel@tonic-gate septmp = ksseplist;
3350Sstevel@tonic-gate for (sp = strchr(kp, (int) *septmp);
3360Sstevel@tonic-gate *(++septmp) && !sp;
337*7934SMark.Phalan@Sun.COM sp = strchr(kp, (int)*septmp)); /* Solaris Kerberos */
3380Sstevel@tonic-gate
3390Sstevel@tonic-gate if (sp) {
3400Sstevel@tonic-gate /* Separate enctype from salttype */
3410Sstevel@tonic-gate sepchar = *sp;
3420Sstevel@tonic-gate *sp = '\0';
3430Sstevel@tonic-gate sp++;
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate else
3460Sstevel@tonic-gate stype = -1;
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate /*
3490Sstevel@tonic-gate * Attempt to parse enctype and salttype. If we parse well
3500Sstevel@tonic-gate * then make sure that it specifies a unique key/salt combo
3510Sstevel@tonic-gate */
3520Sstevel@tonic-gate if (!(kret = krb5_string_to_enctype(kp, &ktype)) &&
3530Sstevel@tonic-gate (!sp || !(kret = krb5_string_to_salttype(sp, &stype))) &&
3540Sstevel@tonic-gate (dups ||
3550Sstevel@tonic-gate !krb5_keysalt_is_present(*ksaltp, *nksaltp, ktype, stype))) {
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate /* Squirrel away old keysalt array */
3580Sstevel@tonic-gate savep = *ksaltp;
3590Sstevel@tonic-gate len = (size_t) *nksaltp;
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate /* Get new keysalt array */
3622881Smp153739 *ksaltp = (krb5_key_salt_tuple *)
3632881Smp153739 malloc((len + 1) * sizeof(krb5_key_salt_tuple));
3642881Smp153739 if (*ksaltp) {
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate /* Copy old keysalt if appropriate */
3670Sstevel@tonic-gate if (savep) {
3680Sstevel@tonic-gate memcpy(*ksaltp, savep,
3690Sstevel@tonic-gate len * sizeof(krb5_key_salt_tuple));
3700Sstevel@tonic-gate krb5_xfree(savep);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate /* Save our values */
3740Sstevel@tonic-gate (*ksaltp)[(*nksaltp)].ks_enctype = ktype;
3750Sstevel@tonic-gate (*ksaltp)[(*nksaltp)].ks_salttype = stype;
3760Sstevel@tonic-gate (*nksaltp)++;
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate else {
3790Sstevel@tonic-gate *ksaltp = savep;
3800Sstevel@tonic-gate break;
3810Sstevel@tonic-gate }
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate /*
3840Sstevel@tonic-gate * Solaris Kerberos
3850Sstevel@tonic-gate * If the string did not yield a valid enctype/keysalt
3860Sstevel@tonic-gate * just ignore it and continue on. MIT kerberos stops
3870Sstevel@tonic-gate * searching when if finds an unknown string.
3880Sstevel@tonic-gate */
3890Sstevel@tonic-gate if (sp)
3900Sstevel@tonic-gate sp[-1] = sepchar;
3910Sstevel@tonic-gate if (ep)
3920Sstevel@tonic-gate ep[-1] = trailchar;
3930Sstevel@tonic-gate kp = ep;
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate /* Skip over extra separators - like spaces */
3960Sstevel@tonic-gate if (kp && *tseplist) {
3970Sstevel@tonic-gate septmp = tseplist;
3980Sstevel@tonic-gate while(*septmp && *kp) {
3990Sstevel@tonic-gate if(*septmp == *kp) {
4000Sstevel@tonic-gate /* Increment string - reset separator list */
4010Sstevel@tonic-gate kp++;
4020Sstevel@tonic-gate septmp = tseplist;
4030Sstevel@tonic-gate } else {
4040Sstevel@tonic-gate septmp++;
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate if (!*kp) kp = NULL;
4080Sstevel@tonic-gate }
4090Sstevel@tonic-gate } /* while kp */
4100Sstevel@tonic-gate return(kret);
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate /*
4140Sstevel@tonic-gate * krb5_keysalt_iterate() - Do something for each unique key/salt
4150Sstevel@tonic-gate * combination.
4160Sstevel@tonic-gate *
4170Sstevel@tonic-gate * If ignoresalt set, then salttype is ignored.
4180Sstevel@tonic-gate */
4190Sstevel@tonic-gate krb5_error_code
krb5_keysalt_iterate(ksaltlist,nksalt,ignoresalt,iterator,arg)4200Sstevel@tonic-gate krb5_keysalt_iterate(ksaltlist, nksalt, ignoresalt, iterator, arg)
4210Sstevel@tonic-gate krb5_key_salt_tuple *ksaltlist;
4220Sstevel@tonic-gate krb5_int32 nksalt;
4230Sstevel@tonic-gate krb5_boolean ignoresalt;
4242881Smp153739 krb5_error_code (*iterator) (krb5_key_salt_tuple *, krb5_pointer);
4250Sstevel@tonic-gate krb5_pointer arg;
4260Sstevel@tonic-gate {
4270Sstevel@tonic-gate int i;
4280Sstevel@tonic-gate krb5_error_code kret;
4290Sstevel@tonic-gate krb5_key_salt_tuple scratch;
4300Sstevel@tonic-gate
4310Sstevel@tonic-gate kret = 0;
4320Sstevel@tonic-gate for (i=0; i<nksalt; i++) {
4330Sstevel@tonic-gate scratch.ks_enctype = ksaltlist[i].ks_enctype;
4340Sstevel@tonic-gate scratch.ks_salttype = (ignoresalt) ? -1 : ksaltlist[i].ks_salttype;
4350Sstevel@tonic-gate if (!krb5_keysalt_is_present(ksaltlist,
4360Sstevel@tonic-gate i,
4370Sstevel@tonic-gate scratch.ks_enctype,
4380Sstevel@tonic-gate scratch.ks_salttype)) {
4392881Smp153739 kret = (*iterator)(&scratch, arg);
4402881Smp153739 if (kret)
4410Sstevel@tonic-gate break;
4420Sstevel@tonic-gate }
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate return(kret);
4450Sstevel@tonic-gate }
446