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

📄 fcache.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
static krb5_error_codeinit_fcc (krb5_context context,	  krb5_ccache id,	  krb5_storage **ret_sp,	  int *ret_fd){    int fd;    int8_t pvno, tag;    krb5_storage *sp;    krb5_error_code ret;    ret = fcc_open(context, id, &fd, O_RDONLY | O_BINARY, 0);    if(ret)	return ret;        sp = krb5_storage_from_fd(fd);    if(sp == NULL) {	krb5_clear_error_string(context);	ret = ENOMEM;	goto out;    }    krb5_storage_set_eof_code(sp, KRB5_CC_END);    ret = krb5_ret_int8(sp, &pvno);    if(ret != 0) {	if(ret == KRB5_CC_END) {	    krb5_set_error_string(context, "Empty credential cache file: %s",				  FILENAME(id));	    ret = ENOENT;	} else	    krb5_set_error_string(context, "Error reading pvno in "				  "cache file: %s", FILENAME(id));	goto out;    }    if(pvno != 5) {	krb5_set_error_string(context, "Bad version number in credential "			      "cache file: %s", FILENAME(id));	ret = KRB5_CCACHE_BADVNO;	goto out;    }    ret = krb5_ret_int8(sp, &tag); /* should not be host byte order */    if(ret != 0) {	krb5_set_error_string(context, "Error reading tag in "			      "cache file: %s", FILENAME(id));	ret = KRB5_CC_FORMAT;	goto out;    }    FCACHE(id)->version = tag;    storage_set_flags(context, sp, FCACHE(id)->version);    switch (tag) {    case KRB5_FCC_FVNO_4: {	int16_t length;	ret = krb5_ret_int16 (sp, &length);	if(ret) {	    ret = KRB5_CC_FORMAT;	    krb5_set_error_string(context, "Error reading tag length in "			      "cache file: %s", FILENAME(id));	    goto out;	}	while(length > 0) {	    int16_t dtag, data_len;	    int i;	    int8_t dummy;	    ret = krb5_ret_int16 (sp, &dtag);	    if(ret) {		krb5_set_error_string(context, "Error reading dtag in "				      "cache file: %s", FILENAME(id));		ret = KRB5_CC_FORMAT;		goto out;	    }	    ret = krb5_ret_int16 (sp, &data_len);	    if(ret) {		krb5_set_error_string(context, "Error reading dlength in "				      "cache file: %s", FILENAME(id));		ret = KRB5_CC_FORMAT;		goto out;	    }	    switch (dtag) {	    case FCC_TAG_DELTATIME :		ret = krb5_ret_int32 (sp, &context->kdc_sec_offset);		if(ret) {		    krb5_set_error_string(context, "Error reading kdc_sec in "					  "cache file: %s", FILENAME(id));		    ret = KRB5_CC_FORMAT;		    goto out;		}		ret = krb5_ret_int32 (sp, &context->kdc_usec_offset);		if(ret) {		    krb5_set_error_string(context, "Error reading kdc_usec in "					  "cache file: %s", FILENAME(id));		    ret = KRB5_CC_FORMAT;		    goto out;		}		break;	    default :		for (i = 0; i < data_len; ++i) {		    ret = krb5_ret_int8 (sp, &dummy);		    if(ret) {			krb5_set_error_string(context, "Error reading unknown "					      "tag in cache file: %s", 					      FILENAME(id));			ret = KRB5_CC_FORMAT;			goto out;		    }		}		break;	    }	    length -= 4 + data_len;	}	break;    }    case KRB5_FCC_FVNO_3:    case KRB5_FCC_FVNO_2:    case KRB5_FCC_FVNO_1:	break;    default :	ret = KRB5_CCACHE_BADVNO;	krb5_set_error_string(context, "Unknown version number (%d) in "			      "credential cache file: %s",			      (int)tag, FILENAME(id));	goto out;    }    *ret_sp = sp;    *ret_fd = fd;        return 0;  out:    if(sp != NULL)	krb5_storage_free(sp);    fcc_unlock(context, fd);    close(fd);    return ret;}static krb5_error_codefcc_get_principal(krb5_context context,		  krb5_ccache id,		  krb5_principal *principal){    krb5_error_code ret;    int fd;    krb5_storage *sp;    ret = init_fcc (context, id, &sp, &fd);    if (ret)	return ret;    ret = krb5_ret_principal(sp, principal);    if (ret)	krb5_clear_error_string(context);    krb5_storage_free(sp);    fcc_unlock(context, fd);    close(fd);    return ret;}static krb5_error_codefcc_end_get (krb5_context context,	     krb5_ccache id,	     krb5_cc_cursor *cursor);static krb5_error_codefcc_get_first (krb5_context context,	       krb5_ccache id,	       krb5_cc_cursor *cursor){    krb5_error_code ret;    krb5_principal principal;    *cursor = malloc(sizeof(struct fcc_cursor));    if (*cursor == NULL) {        krb5_set_error_string (context, "malloc: out of memory");	return ENOMEM;    }    memset(*cursor, 0, sizeof(struct fcc_cursor));    ret = init_fcc (context, id, &FCC_CURSOR(*cursor)->sp, 		    &FCC_CURSOR(*cursor)->fd);    if (ret) {	free(*cursor);	*cursor = NULL;	return ret;    }    ret = krb5_ret_principal (FCC_CURSOR(*cursor)->sp, &principal);    if(ret) {	krb5_clear_error_string(context);	fcc_end_get(context, id, cursor);	return ret;    }    krb5_free_principal (context, principal);    fcc_unlock(context, FCC_CURSOR(*cursor)->fd);    return 0;}static krb5_error_codefcc_get_next (krb5_context context,	      krb5_ccache id,	      krb5_cc_cursor *cursor,	      krb5_creds *creds){    krb5_error_code ret;    if((ret = fcc_lock(context, id, FCC_CURSOR(*cursor)->fd, FALSE)) != 0)	return ret;    ret = krb5_ret_creds(FCC_CURSOR(*cursor)->sp, creds);    if (ret)	krb5_clear_error_string(context);    fcc_unlock(context, FCC_CURSOR(*cursor)->fd);    return ret;}static krb5_error_codefcc_end_get (krb5_context context,	     krb5_ccache id,	     krb5_cc_cursor *cursor){    krb5_storage_free(FCC_CURSOR(*cursor)->sp);    close (FCC_CURSOR(*cursor)->fd);    free(*cursor);    *cursor = NULL;    return 0;}static krb5_error_codefcc_remove_cred(krb5_context context,		 krb5_ccache id,		 krb5_flags which,		 krb5_creds *cred){    krb5_error_code ret;    krb5_ccache copy;    ret = krb5_cc_gen_new(context, &krb5_mcc_ops, &copy);    if (ret)	return ret;    ret = krb5_cc_copy_cache(context, id, copy);    if (ret) {	krb5_cc_destroy(context, copy);	return ret;    }    ret = krb5_cc_remove_cred(context, copy, which, cred);    if (ret) {	krb5_cc_destroy(context, copy);	return ret;    }    fcc_destroy(context, id);    ret = krb5_cc_copy_cache(context, copy, id);    krb5_cc_destroy(context, copy);    return ret;}static krb5_error_codefcc_set_flags(krb5_context context,	      krb5_ccache id,	      krb5_flags flags){    return 0; /* XXX */}static krb5_error_codefcc_get_version(krb5_context context,		krb5_ccache id){    return FCACHE(id)->version;}		    struct fcache_iter {    int first;};static krb5_error_codefcc_get_cache_first(krb5_context context, krb5_cc_cursor *cursor){    struct fcache_iter *iter;    iter = calloc(1, sizeof(*iter));    if (iter == NULL) {	krb5_set_error_string(context, "malloc - out of memory");	return ENOMEM;    }        iter->first = 1;    *cursor = iter;    return 0;}static krb5_error_codefcc_get_cache_next(krb5_context context, krb5_cc_cursor cursor, krb5_ccache *id){    struct fcache_iter *iter = cursor;    krb5_error_code ret;    const char *fn;    char *expandedfn = NULL;    if (!iter->first) {	krb5_clear_error_string(context);	return KRB5_CC_END;    }    iter->first = 0;    fn = krb5_cc_default_name(context);    if (strncasecmp(fn, "FILE:", 5) != 0) {	ret = _krb5_expand_default_cc_name(context, 					   KRB5_DEFAULT_CCNAME_FILE,					   &expandedfn);	if (ret)	    return ret;    }    ret = krb5_cc_resolve(context, fn, id);    if (expandedfn)	free(expandedfn);        return ret;}static krb5_error_codefcc_end_cache_get(krb5_context context, krb5_cc_cursor cursor){    struct fcache_iter *iter = cursor;    free(iter);    return 0;}static krb5_error_codefcc_move(krb5_context context, krb5_ccache from, krb5_ccache to){    krb5_error_code ret = 0;    ret = rename(FILENAME(from), FILENAME(to));    if (ret && errno != EXDEV) {	ret = errno;	krb5_set_error_string(context,			      "Rename of file from %s to %s failed: %s", 			      FILENAME(from), FILENAME(to),			      strerror(ret));	return ret;    } else if (ret && errno == EXDEV) {	/* make a copy and delete the orignal */	krb5_ssize_t sz1, sz2;	int fd1, fd2;	char buf[BUFSIZ];	ret = fcc_open(context, from, &fd1, O_RDONLY | O_BINARY, 0);	if(ret)	    return ret;	unlink(FILENAME(to));	ret = fcc_open(context, to, &fd2, 		       O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600);	if(ret)	    goto out1;	while((sz1 = read(fd1, buf, sizeof(buf))) > 0) {	    sz2 = write(fd2, buf, sz1);	    if (sz1 != sz2) {		ret = EIO;		krb5_set_error_string(context,				      "Failed to write data from one file "				      "credential cache to the other");		goto out2;	    }	}	if (sz1 < 0) {	    ret = EIO;	    krb5_set_error_string(context,				  "Failed to read data from one file "				  "credential cache to the other");	    goto out2;	}	erase_file(FILENAME(from));	        out2:	fcc_unlock(context, fd2);	close(fd2);    out1:	fcc_unlock(context, fd1);	close(fd1);	if (ret) {	    erase_file(FILENAME(to));	    return ret;	}    }    /* make sure ->version is uptodate */    {	krb5_storage *sp;	int fd;	ret = init_fcc (context, to, &sp, &fd);	krb5_storage_free(sp);	fcc_unlock(context, fd);	close(fd);    }        return ret;}static krb5_error_codefcc_default_name(krb5_context context, char **str){    return _krb5_expand_default_cc_name(context, 					KRB5_DEFAULT_CCNAME_FILE,					str);}/** * Variable containing the FILE based credential cache implemention. * * @ingroup krb5_ccache */const krb5_cc_ops krb5_fcc_ops = {    "FILE",    fcc_get_name,    fcc_resolve,    fcc_gen_new,    fcc_initialize,    fcc_destroy,    fcc_close,    fcc_store_cred,    NULL, /* fcc_retrieve */    fcc_get_principal,    fcc_get_first,    fcc_get_next,    fcc_end_get,    fcc_remove_cred,    fcc_set_flags,    fcc_get_version,    fcc_get_cache_first,    fcc_get_cache_next,    fcc_end_cache_get,    fcc_move,    fcc_default_name};

⌨️ 快捷键说明

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