📄 defaultstorageprov.c
字号:
} while (0);
if (dirName != (unsigned char *)0)
Z2Free (dirName);
if (tokens != (unsigned char **)0)
{
for (index = 0; index < tokenCount; ++index)
{
if (tokens[index] != (unsigned char *)0)
Z2Free (tokens[index]);
}
Z2Free (tokens);
}
if (nameList != (VtFileNameList *)0)
VoltFileListFree (libCtx, &nameList);
*newTokenCount = count;
if (status == 0)
return 0;
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltRetrieveNewAuthTokensFromDistrict", (char *)0)
return (status);
}
int VoltDefaultRetrieveNewAuthTokens (
VtStorageCtx storageCtx,
VtDistrictObject reference,
VoltAuthTokenListObject *tokenListObj,
unsigned int *newTokenCount
)
{
return VoltRetrieveNewAuthTokensForDistrict (
storageCtx, reference, tokenListObj,
newTokenCount,VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN);
}
int VoltDefaultRetrieveCurrentDistrictAlloc (
VtStorageCtx storageCtx,
unsigned char *reference,
unsigned int *currentDistrictResult,
unsigned char **currentDistrict,
VtTime *validityStart,
VtTime *validityEnd,
VtTime *timeOfStore
)
{
int status;
unsigned int fileNameLen, contentsLen, nameLen, offset;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
unsigned char *fileName = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
unsigned char *nameCopy = (unsigned char *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
*currentDistrictResult = VOLT_CURRENT_DIST_UNKNOWN;
do
{
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, reference, Z2Strlen (reference),
VOLT_FILE_NAME_VALUE_TYPE_CURR_DIST, &fileName, &fileNameLen);
if (status != 0)
break;
/* Try to open this file.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, fileName, VOLT_FILE_MODE_READ_ONLY, 0);
/* If the return to the open call is ERROR, there was no file to
* open, this function can say nothing about the current district.
* currentDistrictResult was set to VOLT_CURRENT_DIST_UNKNOWN.
*/
if (status == VT_ERROR_FILE_DOES_NOT_EXIST)
{
status = 0;
break;
}
/* Any other error pass on.
*/
if (status != 0)
break;
/* Get the contents of the file.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcLoadDataAlloc (
ctx, fileCtx, fileHandle, (unsigned char *)0, 0, &contents, &contentsLen);
if (status != 0)
break;
/* The first VOLT_TIME_ARRAY_SIZE bytes will be the time of
* store.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_FILE_READ;
if (contentsLen < VOLT_TIME_ARRAY_SIZE)
break;
/* Did the file contain a current district? Or did the file contain
* the information that there is no current district?
* If the only data in the file was time of store, then there is no
* district.
*/
VoltConvertArrayToTime (contents, timeOfStore);
status = 0;
*currentDistrictResult = VOLT_CURRENT_DIST_NO_DIST;
if (contentsLen == VOLT_TIME_ARRAY_SIZE)
break;
/* Has the current district expired? Use timeOfStore as a temp
* variable, get the current time and see if it falls between the
* validityStart and End.
*/
VtGetTime ((VtLibCtx)libCtx, timeOfStore);
offset = VOLT_TIME_ARRAY_SIZE;
VoltConvertArrayToTime (contents + offset, validityStart);
offset += VOLT_TIME_ARRAY_SIZE;
VoltConvertArrayToTime (contents + offset, validityEnd);
offset += VOLT_TIME_ARRAY_SIZE;
/* If the currentDistrict in storage has expired, we'll want to
* download again, so return 0 indicating we successfully
* determined something, and what we determined was
* VOLT_CURRENT_DIST_UNKNOWN.
*/
status = 0;
*currentDistrictResult = VOLT_CURRENT_DIST_UNKNOWN;
if (VoltCompareTime (timeOfStore, validityStart) < 0)
break;
if (VoltCompareTime (validityEnd, timeOfStore) < 0)
break;
VoltConvertArrayToTime (contents, timeOfStore);
/* Build the name with a NULL-terminating character.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
nameLen = contentsLen - offset;
nameCopy = (unsigned char *)Z2Malloc (nameLen + 1, 0);
if (nameCopy == (unsigned char *)0)
break;
Z2Memcpy (nameCopy, contents + offset, nameLen);
nameCopy[nameLen] = 0;
*currentDistrictResult = VOLT_CURRENT_DIST_FOUND;
*currentDistrict = nameCopy;
status = 0;
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile(fileCtx, &fileHandle);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (contents != (unsigned char *)0)
Z2Free (contents);
if (status == 0)
return (0);
/* If there was an error, we won't return this buffer.
*/
if (nameCopy != (unsigned char *)0)
Z2Free (nameCopy);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultRetrieveCurrentDistrictAlloc", (char *)0)
return (status);
}
int VoltDefaultRetrieveDistrictParameters (
VtStorageCtx storageCtx,
VtDistrictObject entry,
unsigned int index,
VtTime *timeOfStore
)
{
int status;
unsigned int fileNameLen, contentsLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltDistrictObject *obj = (VoltDistrictObject *)entry;
unsigned char *fileName = (unsigned char *)0;
unsigned char *nameToUse;
unsigned char *contents = (unsigned char *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VtFileNameList *nameList = (VtFileNameList *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
do
{
/* If the entry obj is already set, error.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_ENTRY;
if ( (obj->paramsText != (unsigned char *)0) ||
(obj->paramObj != (VtParameterObject)0) )
break;
/* If there's no reference, get a list of files.
*/
status = VT_ERROR_INVALID_STORAGE_REF;
if (obj->qualDistrictName.data == (unsigned char *)0)
{
/* If there's no qualified name, there can be no domain name.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (obj->unqualDistrictName.data != (unsigned char *)0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetStorageFileListAlloc (
ctx, VOLT_STORE_DIR_DIST_PARAMS, VOLT_STORE_DIR_DIST_PARAMS_LEN,
0, &nameList);
if (status != 0)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_FOUND;
if (nameList == (VtFileNameList *)0)
break;
if (index >= nameList->nameCount)
break;
nameToUse = nameList->nameList[index];
}
else
{
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, obj->qualDistrictName.data,
obj->qualDistrictName.len, VOLT_FILE_NAME_VALUE_TYPE_DIST_PARAMS,
&fileName, &fileNameLen);
if (status != 0)
break;
nameToUse = fileName;
}
/* Try to open this file.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, nameToUse, VOLT_FILE_MODE_READ_ONLY, 0);
/* If the return to the open call is ERROR, there was no file to
* open, this function indicates no params found.
*/
if (status == VT_ERROR_FILE_DOES_NOT_EXIST)
{
status = VT_ERROR_UNKNOWN_DISTRICT;
break;
}
/* Any other error pass on.
*/
if (status != 0)
break;
/* Get the contents of the file.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcLoadDataAlloc (
ctx, fileCtx, fileHandle, (unsigned char *)0, 0, &contents, &contentsLen);
if (status != 0)
break;
/* The first VOLT_TIME_ARRAY_SIZE bytes will be the time of store.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_FILE_READ;
if (contentsLen < VOLT_TIME_ARRAY_SIZE)
break;
VoltConvertArrayToTime (contents, timeOfStore);
/* The rest of the contents should be the district info.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltSetDistFromParamsText (
contents + VOLT_TIME_ARRAY_SIZE, contentsLen - VOLT_TIME_ARRAY_SIZE,
obj, obj->mpCtx, libCtx);
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile (fileCtx, &fileHandle);
if (nameList != (VtFileNameList *)0)
VoltFileListFree (libCtx, &nameList);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (contents != (unsigned char *)0)
Z2Free (contents);
if (status == 0)
return 0;
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultRetrieveDistrictParameters", (char *)0)
return (status);
}
int VoltDefaultRetrieveIBEPrivateKey (
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtPolicyCtx policyCtx,
unsigned int index,
VtKeyObject keyObj
)
{
int status;
unsigned int fileNameLen, contentsLen, passwordLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
VoltKeyObject *key = (VoltKeyObject *)keyObj;
unsigned char *fileName = (unsigned char *)0;
unsigned char *password = (unsigned char *)0;
unsigned char *nameToUse;
unsigned char *contents = (unsigned char *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VtFileNameList *nameList = (VtFileNameList *)0;
VtDerCoder *derCoders[1] = { VtDerCoderBFType1IBEPrivateKey };
VtSetKeyBerInfo berInfo;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return Vt_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
Z2Memset (&berInfo, 0, sizeof (VtSetKeyBerInfo));
do
{
/* If the keyObj is already set, error.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_KEY_OBJ;
if (key->keyType != 0)
break;
/* If there's no reference, get whatever value is at the index.
*/
if (reference == (VtIdentityObject)0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetStorageFileListAlloc (
ctx, VOLT_STORE_DIR_IBE_KEYS, VOLT_STORE_DIR_IBE_KEYS_LEN,
0, &nameList);
if (status != 0)
break;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_FOUND;
if (nameList == (VtFileNameList *)0)
break;
if (index >= nameList->nameCount)
break;
nameToUse = nameList->nameList[index];
}
else
{
/* We need the identity encoded.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_REF;
if (idObj->encoding.data == (unsigned char *)0)
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -