1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*7c478bd9Sstevel@tonic-gate 8*7c478bd9Sstevel@tonic-gate /* 9*7c478bd9Sstevel@tonic-gate * lib/krb5/ccache/ccbase.c 10*7c478bd9Sstevel@tonic-gate * 11*7c478bd9Sstevel@tonic-gate * Copyright 1990 by the Massachusetts Institute of Technology. 12*7c478bd9Sstevel@tonic-gate * All Rights Reserved. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may 15*7c478bd9Sstevel@tonic-gate * require a specific license from the United States Government. 16*7c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 17*7c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting. 18*7c478bd9Sstevel@tonic-gate * 19*7c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 20*7c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 21*7c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 22*7c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 23*7c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 24*7c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 25*7c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior 26*7c478bd9Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label 27*7c478bd9Sstevel@tonic-gate * your software as modified software and not distribute it in such a 28*7c478bd9Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software. 29*7c478bd9Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of 30*7c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 31*7c478bd9Sstevel@tonic-gate * or implied warranty. 32*7c478bd9Sstevel@tonic-gate * 33*7c478bd9Sstevel@tonic-gate * 34*7c478bd9Sstevel@tonic-gate * Registration functions for ccache. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <k5-int.h> 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate extern krb5_cc_ops *krb5_cc_dfl_ops; 40*7c478bd9Sstevel@tonic-gate struct krb5_cc_typelist 41*7c478bd9Sstevel@tonic-gate { 42*7c478bd9Sstevel@tonic-gate krb5_cc_ops *ops; 43*7c478bd9Sstevel@tonic-gate struct krb5_cc_typelist *next; 44*7c478bd9Sstevel@tonic-gate }; 45*7c478bd9Sstevel@tonic-gate extern krb5_cc_ops krb5_mcc_ops; 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate static struct krb5_cc_typelist cc_entry = { &krb5_mcc_ops, NULL }; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate static struct krb5_cc_typelist *cc_typehead = &cc_entry; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate /* 52*7c478bd9Sstevel@tonic-gate * Register a new credentials cache type 53*7c478bd9Sstevel@tonic-gate * If override is set, replace any existing ccache with that type tag 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 57*7c478bd9Sstevel@tonic-gate KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 58*7c478bd9Sstevel@tonic-gate krb5_cc_register(context, ops, override) 59*7c478bd9Sstevel@tonic-gate krb5_context context; 60*7c478bd9Sstevel@tonic-gate krb5_cc_ops FAR *ops; 61*7c478bd9Sstevel@tonic-gate krb5_boolean override; 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate struct krb5_cc_typelist *t; 64*7c478bd9Sstevel@tonic-gate for (t = cc_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next) 65*7c478bd9Sstevel@tonic-gate ; 66*7c478bd9Sstevel@tonic-gate if (t) { 67*7c478bd9Sstevel@tonic-gate if (override) { 68*7c478bd9Sstevel@tonic-gate t->ops = ops; 69*7c478bd9Sstevel@tonic-gate return 0; 70*7c478bd9Sstevel@tonic-gate } else 71*7c478bd9Sstevel@tonic-gate return KRB5_CC_TYPE_EXISTS; 72*7c478bd9Sstevel@tonic-gate } 73*7c478bd9Sstevel@tonic-gate if (!(t = (struct krb5_cc_typelist *) malloc(sizeof(*t)))) 74*7c478bd9Sstevel@tonic-gate return ENOMEM; 75*7c478bd9Sstevel@tonic-gate t->next = cc_typehead; 76*7c478bd9Sstevel@tonic-gate t->ops = ops; 77*7c478bd9Sstevel@tonic-gate cc_typehead = t; 78*7c478bd9Sstevel@tonic-gate return 0; 79*7c478bd9Sstevel@tonic-gate } 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate /* 82*7c478bd9Sstevel@tonic-gate * Resolve a credential cache name into a cred. cache object. 83*7c478bd9Sstevel@tonic-gate * 84*7c478bd9Sstevel@tonic-gate * The name is currently constrained to be of the form "type:residual"; 85*7c478bd9Sstevel@tonic-gate * 86*7c478bd9Sstevel@tonic-gate * The "type" portion corresponds to one of the predefined credential 87*7c478bd9Sstevel@tonic-gate * cache types, while the "residual" portion is specific to the 88*7c478bd9Sstevel@tonic-gate * particular cache type. 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 92*7c478bd9Sstevel@tonic-gate krb5_cc_resolve (context, name, cache) 93*7c478bd9Sstevel@tonic-gate krb5_context context; 94*7c478bd9Sstevel@tonic-gate const char *name; 95*7c478bd9Sstevel@tonic-gate krb5_ccache *cache; 96*7c478bd9Sstevel@tonic-gate { 97*7c478bd9Sstevel@tonic-gate struct krb5_cc_typelist *tlist; 98*7c478bd9Sstevel@tonic-gate char *pfx, *cp; 99*7c478bd9Sstevel@tonic-gate char *resid; 100*7c478bd9Sstevel@tonic-gate int pfxlen; 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate cp = strchr (name, ':'); 103*7c478bd9Sstevel@tonic-gate if (!cp) { 104*7c478bd9Sstevel@tonic-gate if (krb5_cc_dfl_ops) 105*7c478bd9Sstevel@tonic-gate return (*krb5_cc_dfl_ops->resolve)(context, cache, (char *)name); 106*7c478bd9Sstevel@tonic-gate else 107*7c478bd9Sstevel@tonic-gate return KRB5_CC_BADNAME; 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate pfxlen = cp - name; 111*7c478bd9Sstevel@tonic-gate resid = (char *)name + pfxlen + 1; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate pfx = malloc (pfxlen+1); 114*7c478bd9Sstevel@tonic-gate if (!pfx) 115*7c478bd9Sstevel@tonic-gate return ENOMEM; 116*7c478bd9Sstevel@tonic-gate 117*7c478bd9Sstevel@tonic-gate memcpy (pfx, name, pfxlen); 118*7c478bd9Sstevel@tonic-gate pfx[pfxlen] = '\0'; 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate *cache = (krb5_ccache) 0; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate for (tlist = cc_typehead; tlist; tlist = tlist->next) { 123*7c478bd9Sstevel@tonic-gate if (strcmp (tlist->ops->prefix, pfx) == 0) { 124*7c478bd9Sstevel@tonic-gate free(pfx); 125*7c478bd9Sstevel@tonic-gate return (*tlist->ops->resolve)(context, cache, resid); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate } 128*7c478bd9Sstevel@tonic-gate if (krb5_cc_dfl_ops && !strcmp (pfx, krb5_cc_dfl_ops->prefix)) { 129*7c478bd9Sstevel@tonic-gate free (pfx); 130*7c478bd9Sstevel@tonic-gate return (*krb5_cc_dfl_ops->resolve)(context, cache, resid); 131*7c478bd9Sstevel@tonic-gate } 132*7c478bd9Sstevel@tonic-gate free(pfx); 133*7c478bd9Sstevel@tonic-gate return KRB5_CC_UNKNOWN_TYPE; 134*7c478bd9Sstevel@tonic-gate } 135