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

📄 win32filestore.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:
  /* Keep searching for files until we find no more files.
   */
  index = 0;
  dirExpLen -= (2 * sizeof (WCHAR));

  do
  {
    /* Make sure this is indeed a file and not a directory.
     */ 
    if (findData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
    {
      /* This is a directory. If we're not interested in
       * subdirectories, or if the directory is . or .., move on.
       */
      if (subdirectoriesFlag == 0)
        goto NEXT_FILE;

      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = SubdirectoryQuery (
        libCtx, (unsigned char *)(findData.cFileName), &subdirNameLen);
      if (status != 0)
        break;

      if (subdirNameLen == 0)
        goto NEXT_FILE;

      /* We have a subdirectory. Get its file list.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_MEMORY;
      newDirName = (unsigned char *)Z2Realloc (
        newDirName, dirExpLen + subdirNameLen + sizeof (WCHAR));
      if (newDirName == (unsigned char *)0)
        break;

      Z2Memcpy (newDirName, dirExp, dirExpLen);
      Z2Memcpy (
        newDirName + dirExpLen, findData.cFileName,
        subdirNameLen + sizeof (WCHAR) );

      /* We want to recurse, but to call
       * VoltConvertWideToMultiByteAlloc, we have to pass a UTF-8
       * string.
       */
      VOLT_SET_ERROR_TYPE (errorType, 0);
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltConvertWideToMultiByteAlloc (
        (unsigned short *)newDirName, CP_UTF8, &newDir, libCtx);
      if (status != 0)
        break;

      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGetFileListAlloc (libCtx, newDir, 1, &newNameList);
      if (status != 0)
        break;

      /* Copy the newNameList entries to nameList.
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltCopyFileList (libCtx, newNameList, theList);
      if (status != 0)
        break;

      if (newDir != (unsigned char *)0)
        Z2Free (newDir);
      newDir = (unsigned char *)0;

      if (theList != (VtFileNameList *)0)
        VoltFileListFree (libCtx, &newNameList);
      newNameList = (VtFileNameList *)0;

      goto NEXT_FILE;
    }

    /* We have a file, copy its name.
     *  First, do we have an empty array entry?
     */
    if (theList->listSize == theList->nameCount)
    {
      /* Add 5 more array entries.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_MEMORY;
      theList->nameList = (char **)Z2Realloc (
        theList->nameList, (theList->listSize + 5) * sizeof (char *));
      if (theList->nameList == (char **)0)
        break;
      theArray = (unsigned char *)(theList->nameList);
      theArray += theList->nameCount * sizeof (char *);
      Z2Memset (theArray, 0, 5 * sizeof (char *));

      theList->listSize += 5;
    }            

    /* convert the unicode file name to UTF-8
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltConvertWideToMultiByteAlloc (
      findData.cFileName, CP_UTF8, &utf8_str, libCtx);
    if (status != 0)
      break;

    size = Z2Strlen (utf8_str);
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)    
    status = VT_ERROR_MEMORY;
    theList->nameList[index] = (char *)Z2Malloc (dirNameLen + size + 2, 0);
    if (theList->nameList[index] == (char *)0)
      break;
    status = 0;
    Z2Memcpy (theList->nameList[index], directoryName, dirNameLen);
    Z2Memcpy (theList->nameList[index] + dirNameLen, separator, 1);
    Z2Memcpy (
      theList->nameList[index] + dirNameLen + 1, utf8_str, size);

    Z2Free (utf8_str);
    utf8_str = (unsigned char *)0;

    /* Append a NULL-terminating character.
     */
    theList->nameList[index][dirNameLen + size + 1] = 0;
    theList->nameCount++;
    index++;

    /* If the return is 0, the function found no file.
     */
NEXT_FILE:
    VOLT_SET_FNCT_LINE (fnctLine)
    findRet = FindNextFileW (findHandle, &findData);
    if (findRet == 0)
    {
      /* Why didn't the call find a file? No more files?
       */
      status = 0;
      error = GetLastError ();
      if (error == ERROR_NO_MORE_FILES)
        break;

      status = VT_ERROR_FILE_READ;
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_SYSTEM_ERROR (systemError, error)    
      VOLT_SET_ERROR_DESC(description, "System function FindNextFileW failed")
      break;
    }      

  } while (1);

  /* Free any resources we allocated
   */
  if (theList != (VtFileNameList *)0)
    VoltFileListFree (libCtx, &newNameList);
  if (newDirName != (unsigned char *)0)
    Z2Free (newDirName);
  if (newDir != (unsigned char *)0)
    Z2Free (newDir);
  if (utf8_str != (unsigned char *)0)
    Z2Free (utf8_str);
  if (wide_str != NULL)
    Z2Free (wide_str);  
  if (dirExp  != NULL)
    Z2Free (dirExp);
  if (findHandle != INVALID_HANDLE_VALUE)
    FindClose (findHandle);

  /* If error, free up what we allocated.
   */
  if (status != 0) 
  {
    if (theList != (VtFileNameList *)0)
      VoltFileListFree (libCtx, &theList);

    VOLT_LOG_ERROR_SYSTEM (
    (VtLibCtx)libCtx, status, systemError, errorType, 
    fnctLine, "VoltGetFileListAlloc", description) 

    return status ;
  }

  /* Success, return theList
   */
  *nameList = theList;
  return 0;  
}

static int SubdirectoryQuery (
   VoltLibCtx *libCtx,
   unsigned char *directoryName,
   unsigned int *directoryLen
   )
{
  unsigned int len;
  unsigned char compareBuffer[6] = { 0x2e, 0x00, 0x2e, 0x00 };

  *directoryLen = 0;

  do
  {
    len = wcslen ((unsigned short *)directoryName);
    if (len == 1)
    {
      if ( (directoryName[0] == 0x2e) && (directoryName[1] == 0x00) )
        break;
    }
    else if (len == 2)
    {
      if (Z2Memcmp (directoryName, compareBuffer, 4) == 0)
        break;
    }

    *directoryLen = 2 * len;

  } while (0);

  return (0);
}

int VtStorageParamPasswordManager (
   VtStorageCtx storageCtx,
   Pointer info,
   unsigned int flag
   )
{  
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDefaultStorageCtx *localCtx =
    (VoltDefaultStorageCtx *)(ctx->localStorageCtx);
  VtPasswordManagerCallback *passCtx = (VtPasswordManagerCallback *)0;
  int status;
  
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType)

  do
  {
    /* This StorageParam only does the set operation
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_GET_INFO_UNAVAILABLE;
    if (flag == VOLT_STORAGE_CTX_GET_TYPE_FLAG)
      break;

    /* Check the flag, it should be VOLT_STORAGE_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_STORAGE_CTX_SET_TYPE_FLAG)
      break;
    
    /* Is this a provider that uses a password manager.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_SET;
    if (ctx->SetExtraPassword == (VSetExtraPassword)0)
      break;

    /* If the password manager is already set its an error
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    if (ctx->passwordCtx.PasswordFunction != (VtPasswordManager)0)
      break;

    /* The data associated with this setparam is a pointer to a
     * VtPasswordCtx struct
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    passCtx = (VtPasswordManagerCallback *)info;
    if (passCtx->PasswordFunction == (VtPasswordManager)0)
      break;

    /* Make sure that if there is a data copy function there is a data free
     * function too.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    if ( (passCtx->AppDataCopy != (VtPasswordAppDataCopy)0) &&
         (passCtx->AppDataFree == (VtPasswordAppDataFree)0)  )
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    if ( (passCtx->AppDataCopy == (VtPasswordAppDataCopy)0) &&
         (passCtx->AppDataFree != (VtPasswordAppDataFree)0)  )
      break;

    ctx->passwordCtx.PasswordFunction = passCtx->PasswordFunction;
    ctx->passwordCtx.AppDataCopy = passCtx->AppDataCopy ;
    ctx->passwordCtx.AppDataFree = passCtx->AppDataFree ;
    ctx->passwordCtx.appData = passCtx->appData ;
    if ( (passCtx->AppDataCopy != (VtPasswordAppDataCopy)0) &&
         (passCtx->appData != (Pointer)0) )
    {
      ctx->passwordCtx.appData = (Pointer)0;
      status = passCtx->AppDataCopy (
        (VtLibCtx)libCtx, passCtx->appData, &(ctx->passwordCtx.appData));
      if (status != 0)
        break;
    }  

    status = 0;

  } while (0);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VtStorageParamPasswordManager", (char *)0)

  return (status);
}

int VtStorageParamWinExtraPassword (
   VtStorageCtx storageCtx,
   Pointer info,
   unsigned int flag
   )
{
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;  
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  int status;
  
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType)

  do
  {
    /* This StorageParam only does the set operation
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_GET_INFO_UNAVAILABLE;
    if (flag == VOLT_STORAGE_CTX_GET_TYPE_FLAG)
      break;

    /* Check the flag, it should be VOLT_STORAGE_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_STORAGE_CTX_SET_TYPE_FLAG)
      break;

    /* Is this a provider that uses an extra password?
     */
    VOLT_SET_FNCT_LINE (fnctLine)    
    if (ctx->SetExtraPassword == (VSetExtraPassword)0)
      break;

    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = ctx->SetExtraPassword (storageCtx, info);

  } while (0);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VtStorageParamWinExtraPassword", (char *)0)

  return (status);
}

int VoltWinSetExtraPassword (
   VtStorageCtx storageCtx,
   Pointer info
   )
{
  int status, deletePasswordFile, cmpResult;
  unsigned int purpose, passwordLen, oldPasswordLen, iterationCount;
  unsigned int oldHmacLen, newHmacLen, algIdLen, saltLen, passwordInfoLen;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDefaultStorageCtx *localCtx =
    (VoltDefaultStorageCtx *)(ctx->localStorageCtx);
  VtRandomObject random = (VtRandomObject)0;
  VtPasswordManager PasswordManager = (VtPasswordManager)0;
  VtAlgorithmImpl *DigestImpl = (VtAlgorithmImpl *)0;
  VoltFileCtx *fileCtx = localCtx->fCtx;
  VoltFileHandle fileHandle = (VoltFileHandle)0;
  unsigned char *fileName = (unsigned char *)0;

⌨️ 快捷键说明

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