localpolicy.c
来自「IBE是一种非对称密码技术」· C语言 代码 · 共 249 行
C
249 行
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "policy.h"
#include "localpolicy.h"
#include "voltfile.h"
#include "errorctx.h"
int VoltLocalPolicyGetInfoAlloc (
VtPolicyCtx policyCtx,
VoltPolicyGetType policyGetType,
Pointer definition,
Pointer *info
);
void VoltLocalPolicyGetInfoFree (
VtPolicyCtx policyCtx,
Pointer info
);
void VoltLocalPolicyCtxDestroy (
Pointer obj,
Pointer ctx
);
/* String based Policy implementation. Policy is provided in an
* XML string.
*/
int VtPolicyImplXmlBuffer (
VtPolicyCtx *policyCtx,
Pointer info,
unsigned int flag
)
{
int status;
VoltPolicyCtx *ctx = (VoltPolicyCtx *)(*policyCtx);
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
unsigned char *buffer = (unsigned char *)0;
VoltDefaultPolicyCtx *localPolicyCtx = (VoltDefaultPolicyCtx *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_POLICY_CTX_SET_TYPE_FLAG)
break;
/* The associated info should be a char array.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
/* Allocate space for the local ctx, VoltDefaultPolicyCtx.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
buffer = (unsigned char *)Z2Malloc (sizeof (VoltDefaultPolicyCtx), 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, sizeof (VoltDefaultPolicyCtx));
localPolicyCtx = (VoltDefaultPolicyCtx *)buffer;
/* Create the client policy.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
localPolicyCtx->vsPolicyObj = m_vs_cp_new (
(VtLibCtx)libCtx, (char *)info);
if (localPolicyCtx->vsPolicyObj == (mVsClientPolicyT *)0)
break;
/* Set the fields of the policyCtx.
*/
ctx->localCtx = (Pointer)localPolicyCtx;
ctx->LocalCtxDestroy = VoltLocalPolicyCtxDestroy;
ctx->PolicyGetInfoAlloc = VoltLocalPolicyGetInfoAlloc;
ctx->PolicyGetInfoFree = VoltLocalPolicyGetInfoFree;
status = 0;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, destroy anything we created.
*/
if (localPolicyCtx != (VoltDefaultPolicyCtx *)0)
{
if (localPolicyCtx->vsPolicyObj != (mVsClientPolicyT *)0)
m_vs_cp_free (localPolicyCtx->vsPolicyObj);
}
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR_INFO (
0, *policyCtx, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VtPolicyImplXmlBuffer", fnctLine, (char *)0)
return (status);
}
int VtPolicyImplXmlFile (
VtPolicyCtx *policyCtx,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int bytesRead;
VoltFileInt fileSize;
VoltPolicyCtx *ctx = (VoltPolicyCtx *)(*policyCtx);
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VtFileCtxUseInfo *fileInfo;
VtFileCtx fileCtxToUse;
VoltFileHandle fileHandle = (VoltFileHandle)0;
char *xmlString = (char *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Check the flag, it should be VOLT_POLICY_CTX_SET_TYPE_FLAG.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_POLICY_CTX_SET_TYPE_FLAG)
break;
/* The info must be the FileCtxUseInfo.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
fileInfo = (VtFileCtxUseInfo *)info;
if (fileInfo->path == (unsigned char *)0)
break;
/* If there's no fileCtx in the info, get one from the libCtx. If
* there's not one there, error.
*/
fileCtxToUse = fileInfo->fileCtx;
if (fileCtxToUse == (VtFileCtx)0)
{
fileCtxToUse = (VtFileCtx)VoltGetLibCtxInfo (
(VtLibCtx)libCtx, VOLT_LIB_CTX_INFO_TYPE_FILE_CTX);
VOLT_SET_FNCT_LINE (fnctLine)
if (fileCtxToUse == (VtFileCtx)0)
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
if (VOLT_OBJECT_TYPE_NOT_EQUAL (fileCtxToUse, VOLT_OBJECT_TYPE_FILE_CTX))
break;
/* What we read from the file is simply the XML string that is
* the argument to VtPolicyImplXmlBuffer. So download that string,
* then call VtPolicyImplXmlBuffer.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtxToUse->CtxOpenFile (
fileCtxToUse, &fileHandle, fileInfo->path,
VOLT_FILE_MODE_READ_ONLY, 0);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtxToUse->CtxGetFileSize (
fileCtxToUse, fileHandle, (char *)0, &fileSize);
if (status != 0)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
xmlString = (char *)Z2Malloc (fileSize + 1, 0);
if (xmlString == (char *)0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtxToUse->CtxReadFile (
fileCtxToUse, fileHandle, (unsigned int)fileSize, xmlString, &bytesRead);
if (status != 0)
break;
xmlString[bytesRead] = 0;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtPolicyImplXmlBuffer (policyCtx, (Pointer)xmlString, flag);
} while (0);
if (xmlString != (char *)0)
Z2Free (xmlString);
if (fileHandle != (VoltFileHandle)0)
fileCtxToUse->CtxCloseFile (fileCtxToUse, &fileHandle);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, *policyCtx, status, 0, errorType,
(char *)0, "VtPolicyImplXmlFile", fnctLine, (char *)0)
return (status);
}
void VoltLocalPolicyCtxDestroy (
Pointer obj,
Pointer ctx
)
{
VoltPolicyCtx *policyCtx = (VoltPolicyCtx *)obj;
VoltLibCtx *libCtx;
VoltDefaultPolicyCtx *localPolicyCtx = (VoltDefaultPolicyCtx *)ctx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(policyCtx->voltObject.libraryCtx);
/* Destroy the contents of the localCtx.
*/
if (localPolicyCtx->vsPolicyObj != (mVsClientPolicyT *)0)
m_vs_cp_free (localPolicyCtx->vsPolicyObj);
/* Free up the localCtx.
*/
Z2Free (ctx);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?