git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2440 ec53bebd-3082-4978-b11e-865c3cabbd6b
		
			
				
	
	
		
			186 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			186 lines
		
	
	
		
			4.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 1997 Kungliga Tekniska Högskolan
 | 
						|
 * (Royal Institute of Technology, Stockholm, Sweden). 
 | 
						|
 * All rights reserved. 
 | 
						|
 *
 | 
						|
 * Redistribution and use in source and binary forms, with or without 
 | 
						|
 * modification, are permitted provided that the following conditions 
 | 
						|
 * are met: 
 | 
						|
 *
 | 
						|
 * 1. Redistributions of source code must retain the above copyright 
 | 
						|
 *    notice, this list of conditions and the following disclaimer. 
 | 
						|
 *
 | 
						|
 * 2. Redistributions in binary form must reproduce the above copyright 
 | 
						|
 *    notice, this list of conditions and the following disclaimer in the 
 | 
						|
 *    documentation and/or other materials provided with the distribution. 
 | 
						|
 *
 | 
						|
 * 3. All advertising materials mentioning features or use of this software 
 | 
						|
 *    must display the following acknowledgement: 
 | 
						|
 *      This product includes software developed by Kungliga Tekniska 
 | 
						|
 *      Högskolan and its contributors. 
 | 
						|
 *
 | 
						|
 * 4. Neither the name of the Institute nor the names of its contributors 
 | 
						|
 *    may be used to endorse or promote products derived from this software 
 | 
						|
 *    without specific prior written permission. 
 | 
						|
 *
 | 
						|
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
 | 
						|
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 | 
						|
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 | 
						|
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
 | 
						|
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 | 
						|
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 | 
						|
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 | 
						|
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 | 
						|
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 | 
						|
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 | 
						|
 * SUCH DAMAGE. 
 | 
						|
 */
 | 
						|
 | 
						|
#include "krb5_locl.h"
 | 
						|
 | 
						|
RCSID("$Id$");
 | 
						|
 | 
						|
krb5_error_code
 | 
						|
krb5_init_context(krb5_context *context)
 | 
						|
{
 | 
						|
    krb5_context p;
 | 
						|
    const char *tmp;
 | 
						|
    ALLOC(p, 1);
 | 
						|
    if(!p)
 | 
						|
	return ENOMEM;
 | 
						|
    memset(p, 0, sizeof(krb5_context_data));
 | 
						|
    krb5_init_ets(p);
 | 
						|
    p->cc_ops = NULL;
 | 
						|
    krb5_config_parse_file (krb5_config_file, &p->cf);
 | 
						|
    p->max_skew = 5 * 60;
 | 
						|
    tmp = krb5_config_get_string (p->cf, "libdefaults", "clockskew", NULL);
 | 
						|
    if(tmp){
 | 
						|
	unsigned val;
 | 
						|
	if(sscanf(tmp, "%u", &val) == 1)
 | 
						|
	    p->max_skew = val;
 | 
						|
    }
 | 
						|
    p->kdc_timeout = 3;
 | 
						|
    tmp = krb5_config_get_string (p->cf, "libdefaults", "kdc_timeout", NULL);
 | 
						|
    if(tmp){
 | 
						|
	unsigned val;
 | 
						|
	if(sscanf(tmp, "%u", &val) == 1)
 | 
						|
	    p->kdc_timeout = val;
 | 
						|
    }
 | 
						|
    krb5_set_default_realm(p, NULL);
 | 
						|
    *context = p;
 | 
						|
    return 0;
 | 
						|
}
 | 
						|
 | 
						|
void
 | 
						|
krb5_free_context(krb5_context context)
 | 
						|
{
 | 
						|
  int i;
 | 
						|
 | 
						|
  free(context->etypes);
 | 
						|
  free(context->default_realm);
 | 
						|
  krb5_config_file_free (context->cf);
 | 
						|
  free_error_table (context->et_list);
 | 
						|
  for(i = 0; i < context->num_ops; ++i)
 | 
						|
    free(context->cc_ops[i].prefix);
 | 
						|
  free(context->cc_ops);
 | 
						|
  free(context);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
/*
 | 
						|
 * XXX - This information needs to be coordinated with encrypt.c
 | 
						|
 */
 | 
						|
 | 
						|
static krb5_boolean
 | 
						|
valid_etype(krb5_enctype e)
 | 
						|
{
 | 
						|
  return e == ETYPE_DES_CBC_CRC
 | 
						|
      || e == ETYPE_DES_CBC_MD4
 | 
						|
      || e == ETYPE_DES_CBC_MD5;
 | 
						|
}
 | 
						|
 | 
						|
static krb5_error_code
 | 
						|
default_etypes(krb5_enctype **etype)
 | 
						|
{
 | 
						|
  krb5_enctype *p;
 | 
						|
  ALLOC(p, 4);
 | 
						|
  if(!p)
 | 
						|
    return ENOMEM;
 | 
						|
  p[0] = ETYPE_DES_CBC_MD5;
 | 
						|
  p[1] = ETYPE_DES_CBC_MD4;
 | 
						|
  p[2] = ETYPE_DES_CBC_CRC;
 | 
						|
  p[3] = 0;
 | 
						|
  *etype = p;
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 | 
						|
krb5_error_code
 | 
						|
krb5_set_default_in_tkt_etypes(krb5_context context, 
 | 
						|
			       const krb5_enctype *etypes)
 | 
						|
{
 | 
						|
  int i;
 | 
						|
  krb5_enctype *p = NULL;
 | 
						|
 | 
						|
  if(etypes) {
 | 
						|
    i = 0;
 | 
						|
    while(etypes[i])
 | 
						|
      if(!valid_etype(etypes[i++]))
 | 
						|
	return KRB5_PROG_ETYPE_NOSUPP;
 | 
						|
    ++i;
 | 
						|
    ALLOC(p, i);
 | 
						|
    if(!p)
 | 
						|
      return ENOMEM;
 | 
						|
    memmove(p, etypes, i * sizeof(krb5_enctype));
 | 
						|
  }
 | 
						|
  if(context->etypes)
 | 
						|
    free(context->etypes);
 | 
						|
  context->etypes = p;
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
krb5_error_code
 | 
						|
krb5_get_default_in_tkt_etypes(krb5_context context,
 | 
						|
			       krb5_enctype **etypes)
 | 
						|
{
 | 
						|
  krb5_enctype *p;
 | 
						|
  int i;
 | 
						|
 | 
						|
  if(context->etypes) {
 | 
						|
    for(i = 0; context->etypes[i]; i++);
 | 
						|
    ++i;
 | 
						|
    ALLOC(p, i);
 | 
						|
    if(!p)
 | 
						|
      return ENOMEM;
 | 
						|
    memmove(p, context->etypes, i * sizeof(krb5_enctype));
 | 
						|
  } else
 | 
						|
    if(default_etypes(&p))
 | 
						|
      return ENOMEM;
 | 
						|
  *etypes = p;
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 | 
						|
const char *
 | 
						|
krb5_get_err_text(krb5_context context, long code)
 | 
						|
{
 | 
						|
    const char *p = com_right(context->et_list, code);
 | 
						|
    if(p == NULL)
 | 
						|
	p = strerror(code);
 | 
						|
    return p;
 | 
						|
}
 | 
						|
 | 
						|
void
 | 
						|
krb5_init_ets(krb5_context context)
 | 
						|
{
 | 
						|
    if(context->et_list == NULL){
 | 
						|
	initialize_krb5_error_table(&context->et_list);
 | 
						|
#if 0
 | 
						|
	initialize_kv5m_error_table(&context->et_list);
 | 
						|
	initialize_kdb5_error_table(&context->et_list);
 | 
						|
#endif
 | 
						|
	initialize_asn1_error_table(&context->et_list);
 | 
						|
	initialize_hdb_error_table(&context->et_list);
 | 
						|
    }
 | 
						|
}
 |