⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache.c

📁 samba最新软件
💻 C
字号:
/* * Copyright (c) 1997 - 2007 Kungliga Tekniska H鰃skolan * (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. 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: cache.c 22127 2007-12-04 00:54:37Z lha $");/** * Add a new ccache type with operations `ops', overwriting any * existing one if `override'. * * @param context a Keberos context * @param ops type of plugin symbol * @param override flag to select if the registration is to overide * an existing ops with the same name. * * @return Return an error code or 0. * * @ingroup krb5_ccache */krb5_error_code KRB5_LIB_FUNCTIONkrb5_cc_register(krb5_context context, 		 const krb5_cc_ops *ops, 		 krb5_boolean override){    int i;    for(i = 0; i < context->num_cc_ops && context->cc_ops[i].prefix; i++) {	if(strcmp(context->cc_ops[i].prefix, ops->prefix) == 0) {	    if(!override) {		krb5_set_error_string(context,				      "ccache type %s already exists",				      ops->prefix);		return KRB5_CC_TYPE_EXISTS;	    }	    break;	}    }    if(i == context->num_cc_ops) {	krb5_cc_ops *o = realloc(context->cc_ops,				 (context->num_cc_ops + 1) *				 sizeof(*context->cc_ops));	if(o == NULL) {	    krb5_set_error_string(context, "malloc: out of memory");	    return KRB5_CC_NOMEM;	}	context->num_cc_ops++;	context->cc_ops = o;	memset(context->cc_ops + i, 0, 	       (context->num_cc_ops - i) * sizeof(*context->cc_ops));    }    memcpy(&context->cc_ops[i], ops, sizeof(context->cc_ops[i]));    return 0;}/* * Allocate the memory for a `id' and the that function table to * `ops'. Returns 0 or and error code. */krb5_error_code_krb5_cc_allocate(krb5_context context, 		  const krb5_cc_ops *ops,		  krb5_ccache *id){    krb5_ccache p;    p = malloc (sizeof(*p));    if(p == NULL) {	krb5_set_error_string(context, "malloc: out of memory");	return KRB5_CC_NOMEM;    }    p->ops = ops;    *id = p;    return 0;}/* * Allocate memory for a new ccache in `id' with operations `ops' * and name `residual'. Return 0 or an error code. */static krb5_error_codeallocate_ccache (krb5_context context,		 const krb5_cc_ops *ops,		 const char *residual,		 krb5_ccache *id){    krb5_error_code ret;    ret = _krb5_cc_allocate(context, ops, id);    if (ret)	return ret;    ret = (*id)->ops->resolve(context, id, residual);    if(ret)	free(*id);    return ret;}/** * Find and allocate a ccache in `id' from the specification in `residual'. * If the ccache name doesn't contain any colon, interpret it as a file name. * * @param context a Keberos context. * @param name string name of a credential cache. * @param id return pointer to a found credential cache. * * @return Return 0 or an error code. In case of an error, id is set * to NULL. * * @ingroup krb5_ccache */krb5_error_code KRB5_LIB_FUNCTIONkrb5_cc_resolve(krb5_context context,		const char *name,		krb5_ccache *id){    int i;    *id = NULL;    for(i = 0; i < context->num_cc_ops && context->cc_ops[i].prefix; i++) {	size_t prefix_len = strlen(context->cc_ops[i].prefix);	if(strncmp(context->cc_ops[i].prefix, name, prefix_len) == 0	   && name[prefix_len] == ':') {	    return allocate_ccache (context, &context->cc_ops[i],				    name + prefix_len + 1,				    id);	}    }    if (strchr (name, ':') == NULL)	return allocate_ccache (context, &krb5_fcc_ops, name, id);    else {	krb5_set_error_string(context, "unknown ccache type %s", name);	return KRB5_CC_UNKNOWN_TYPE;    }}/** * Generate a new ccache of type `ops' in `id'. * * @return Return 0 or an error code. * * @ingroup krb5_ccache */krb5_error_code KRB5_LIB_FUNCTIONkrb5_cc_gen_new(krb5_context context,		const krb5_cc_ops *ops,		krb5_ccache *id){    return krb5_cc_new_unique(context, ops->prefix, NULL, id);}/** * Generates a new unique ccache of `type` in `id'. If `type' is NULL, * the library chooses the default credential cache type. The supplied * `hint' (that can be NULL) is a string that the credential cache * type can use to base the name of the credential on, this is to make * it easier for the user to differentiate the credentials. * * @return Returns 0 or an error code. * * @ingroup krb5_ccache */krb5_error_code KRB5_LIB_FUNCTIONkrb5_cc_new_unique(krb5_context context, const char *type, 		   const char *hint, krb5_ccache *id){    const krb5_cc_ops *ops = KRB5_DEFAULT_CCTYPE;    krb5_error_code ret;    if (type) {	ops = krb5_cc_get_prefix_ops(context, type);	if (ops == NULL) {	    krb5_set_error_string(context,				  "Credential cache type %s is unknown", type);	    return KRB5_CC_UNKNOWN_TYPE;	}    }    ret = _krb5_cc_allocate(context, ops, id);    if (ret)	return ret;    return (*id)->ops->gen_new(context, id);}/** * Return the name of the ccache `id' * * @ingroup krb5_ccache */const char* KRB5_LIB_FUNCTIONkrb5_cc_get_name(krb5_context context,		 krb5_ccache id){    return id->ops->get_name(context, id);}/** * Return the type of the ccache `id'. * * @ingroup krb5_ccache */const char* KRB5_LIB_FUNCTIONkrb5_cc_get_type(krb5_context context,		 krb5_ccache id){    return id->ops->prefix;}/** * Return the complete resolvable name the ccache `id' in `str

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -