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

📄 macosxfilestore.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
📖 第 1 页 / 共 2 页
字号:
       * We can't work. return error       */      if( fCtx == (VtFileCtx) 0 )        break;          }    /* Create the local ctx along with the pathName.     */        status = VT_ERROR_MEMORY;    bufferSize =      sizeof (VoltDefaultStorageCtx) + sizeof (mIcStoreCtx) +      pathNameLen + 1 ;#if VOLT_ALIGNMENT != 1    /* If the alignment is 1, there's no need to pad. If not, compute     * the pad length.     */    VOLT_COMPUTE_ALIGN_PAD      (VOLT_ALIGNMENT, sizeof (VoltDefaultStorageCtx), pad)    bufferSize += pad;#endif    VOLT_SET_FNCT_LINE (fnctLine)    buffer = (unsigned char *)Z2Malloc (bufferSize, 0);    if (buffer == (unsigned char *)0)      break;    Z2Memset (buffer, 0, bufferSize);    /* Set the fields.     */    localCtx = (VoltDefaultStorageCtx *)buffer;    offset = sizeof (VoltDefaultStorageCtx);#if VOLT_ALIGNMENT != 1    offset += pad;#endif    localCtx->icStoreCtx = (Pointer)(buffer + offset);    if (pathNameLen != 0)    {      offset += sizeof (mIcStoreCtx);      localCtx->pathName = (char *)(buffer + offset);      Z2Memcpy (localCtx->pathName, pathName, pathNameLen);      localCtx->pathNameLen = pathNameLen;    }    /* Clone the File context object to keep a local copy    * of file context. We may need it later..    */    VOLT_SET_ERROR_TYPE (errorType, 0)    VOLT_SET_FNCT_LINE (fnctLine)    status = VtCloneObject ((Pointer)fCtx, (Pointer *)&(localCtx->fCtx) );    if( status != 0)        break;    VOLT_SET_FNCT_LINE (fnctLine)    status = mIcStorageSetup (      libCtx, (mIcStoreCtx *)(localCtx->icStoreCtx));    if (status != 0)      break;    /* Set the fields of the provider struct.     */    ctx->providerNum                  = providerNum;    ctx->storageTypeFlag              = VOLT_STORAGE_TYPE_TOOLKIT;    ctx->localStorageCtx              = (Pointer)localCtx;    ctx->LocalStorageCtxDestroy       = VoltDefaultStorageCtxDestroy;    ctx->SetExtraPassword             = VoltDefaultSetExtraPassword;    ctx->GetEnvelopeKey               = VoltDefaultGetEnvelopeKey;    ctx->StoreCurrentDistrict         = VoltDefaultStoreCurrentDistrict;    ctx->StoreDistrictParameters      = VoltDefaultStoreDistrictParameters;    ctx->StoreAuthToken               = VoltDefaultStoreAuthToken;    ctx->StoreIBEPrivateKey           = VoltDefaultStoreIBEPrivateKey;    ctx->StorePrivateSigningKey       = VoltDefaultStorePrivateSigningKey;    ctx->StorePublicSigningCert       = VoltDefaultStorePublicSigningCert;    ctx->GetDistrictParameterCount    = VoltDefaultGetDistrictParameterCount;    ctx->GetIBEPrivateKeyCount        = VoltDefaultGetIBEPrivateKeyCount;    ctx->GetPrivateSigningKeyCount    = VoltDefaultGetPrivateSigningKeyCount;    ctx->GetPublicSigningCertCount    = VoltDefaultGetPublicSigningCertCount;    ctx->GetAuthTokenCount            = VoltDefaultGetAuthTokenCount;    ctx->RetrieveNewAuthTokens        = VoltDefaultRetrieveNewAuthTokens;    ctx->RetrieveCurrentDistrictAlloc = VoltDefaultRetrieveCurrentDistrictAlloc;    ctx->RetrieveDistrictParameters   = VoltDefaultRetrieveDistrictParameters;    ctx->RetrieveIBEPrivateKey        = VoltDefaultRetrieveIBEPrivateKey;    ctx->RetrievePrivateSigningKey    = VoltDefaultRetrievePrivateSigningKey;    ctx->RetrievePublicSigningCert    = VoltDefaultRetrievePublicSigningCert;    ctx->DeleteCurrentDistrict        = VoltDefaultDeleteCurrentDistrict;    ctx->DeleteDistrictParameters     = VoltDefaultDeleteDistrictParameters;    ctx->DeleteIBEPrivateKey          = VoltDefaultDeleteIBEPrivateKey;    ctx->DeletePrivateSigningKey      = VoltDefaultDeletePrivateSigningKey;    ctx->DeletePublicSigningCert      = VoltDefaultDeletePublicSigningCert;    ctx->DeleteAuthToken              = VoltDefaultDeleteAuthToken;  } while (0);  /* If success, we're done.   */  if (status == 0)    return (0);  /* If error, free up any memory we allocated.   */  VoltDefaultStorageCtxDestroy ((Pointer)storageCtx, (Pointer) localCtx);    return (status);}int getICDirectory (  VoltLibCtx *libCtx,  unsigned char *buf,  int bufLen  ){    char *VoltageName = ".Voltage"; /* hidden directory */  char *home_dir;  char *cur_dir = (char *)0 ;  char *dir_path;  int len, VoltageNameLen;     Z2Memset (buf, 0, bufLen);  VoltageNameLen = Z2Strlen (VoltageName);  /* The default directory where the crypto data is stored   * is <HOME_DIR>/.Voltage   */  home_dir = getenv ("HOME");  dir_path = home_dir;  /* unlikely but getenv can return NULL for home dir   * In that case use current dir   */  if (home_dir == (char *)0 )   {    cur_dir = getcwd ( (char *)0, VOLT_MAX_PATH );    dir_path = cur_dir;      }  do   {    /* If we still don't have a valid path return empty string     * No need to free cur_dir var.     */    if ( dir_path == (char *)0 )     {      buf[0] = '\0';      break;    }    len = Z2Strlen (dir_path);    /* Full path is dir_path + '/' + ".Voltage"     */    if ( bufLen < len + VoltageNameLen + 2 )      break;    /* dir_path may point to a memory that belongs to the system     * Don't modify the pointers returned by getenv function     * instead make a copy and use it     */    Z2Memcpy (buf, dir_path, len);     /* Append /Voltage to the buf + string terminationg character.     */    buf[len] = '/';    Z2Memcpy (buf + len +1, VoltageName, VoltageNameLen+1);  } while (0);  /* Free any memory that was allocated by getcwd. Since getcwd uses  *  malloc to allocate the memory we must use free to free it.   */  if (cur_dir != (char *)0 )    free (cur_dir);

  return (0);}int VoltGetFileListAlloc (  VoltLibCtx *libCtx,  unsigned char *directoryName,  unsigned int subdirectoriesFlag,  VtFileNameList **nameList   ){   unsigned int status;  unsigned int nameLen, dirLen;  unsigned char *path = (unsigned char *)0;  VtFileNameList *theList = (VtFileNameList *)0;  char *theArray1 = (Pointer)0;    char *theArray2 = (Pointer)0;  DIR *dir = (DIR *)0;  struct dirent *entry = (struct dirent *)0;  VtFileNameList *newNameList = (VtFileNameList *)0;    VOLT_DECLARE_ERROR_TYPE (errorType)  VOLT_DECLARE_SYSTEM_ERROR (systemError)  VOLT_DECLARE_ERROR_DESC (description)   VOLT_DECLARE_FNCT_LINE (fnctLine)  *nameList = (VtFileNameList *)0;  dirLen = Z2Strlen (directoryName);  status = 0;  do   {    /* Open the directory passed    */    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)    VOLT_SET_FNCT_LINE (fnctLine)    dir = opendir (directoryName);    if (dir == (DIR *) 0 )     {      status = 0;      if (errno == ENOENT)        break;      /* Any other error is an actual error      */      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)      VOLT_SET_SYSTEM_ERROR (systemError, errno)          VOLT_SET_ERROR_DESC(description, "System function opendir failed")      break;    }        /* Build the list struct, the shell.    */      status = VT_ERROR_MEMORY;    VOLT_SET_FNCT_LINE (fnctLine)    theList = (VtFileNameList *)Z2Malloc (sizeof (VtFileNameList), 0);    if (theList == (VtFileNameList *)0)       break;       Z2Memset (theList, 0, sizeof (VtFileNameList));    /* Build an initial array of size 5.    */    status = VT_ERROR_MEMORY;    VOLT_SET_FNCT_LINE (fnctLine)    theArray1 = (char *)Z2Malloc (5 * sizeof (char *), 0);    if (theArray1 == (char *)0)            break;        Z2Memset (theArray1, 0, 5 * sizeof (char *));    theList->nameList = (char **)theArray1;    theList->listSize = 5;    theArray1 = (char *)0;        /* Keep searching for files until we find no more files.    */        while (1)    {      struct stat buf;      unsigned int len;      entry = readdir (dir);      if (entry == (struct dirent *)0)      {        VOLT_SET_FNCT_LINE (fnctLine)        status = 0;        if (errno == 0)          break;        /* Any other error is an actual error        */        VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)        VOLT_SET_SYSTEM_ERROR (systemError, errno)            VOLT_SET_ERROR_DESC(description, "System function readdir failed")        break;      }      /* If the directory name is . or .. then continue      */      if (Z2Strcmp (".", entry->d_name) == 0)        goto NEXT_FILE;      if (Z2Strcmp ("..", entry->d_name) == 0)        goto NEXT_FILE;             len = Z2Strlen (entry->d_name);       VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)      VOLT_SET_FNCT_LINE (fnctLine)      status = VT_ERROR_MEMORY;      path = (unsigned char *)Z2Malloc (dirLen + len + 2, 0);      if (path == (unsigned char *)0)        break;            Z2Memcpy (path, directoryName, dirLen);      path [dirLen] = '/';      Z2Memcpy (path + dirLen + 1, entry->d_name, len + 1);            /* If the path represents a directory continue      */       VOLT_SET_FNCT_LINE (fnctLine)      if (stat (path , &buf) < 0 )       {                VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_SYSTEM | VT_ERROR_TYPE_PRIMARY)        VOLT_SET_SYSTEM_ERROR (systemError, errno)            VOLT_SET_ERROR_DESC(description, "System function stat failed")        status = VT_ERROR_FILE_ATTRIBUTES;        break;      }            if (S_ISDIR (buf.st_mode) )       {        /* If we don't want to look into subdirectories, continue.        */        if (subdirectoriesFlag == 0)          goto NEXT_FILE;        /* We want to find the files in the subdirectory        */        VOLT_SET_ERROR_TYPE (errorType, 0)        VOLT_SET_FNCT_LINE (fnctLine)        status = VoltGetFileListAlloc (libCtx, path, 1, &newNameList);        if (status != 0)          break;        /* copy the subdir list to the existing file list        */        VOLT_SET_FNCT_LINE (fnctLine)        status = VoltCopyFileList (libCtx, newNameList, theList);        if (status != 0)          break;        if (newNameList != (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;        theArray2 = (char *)Z2Malloc (          (theList->listSize + 5) * sizeof (char *), 0);        if (theArray2 == (char *)0)          break;        Z2Memset (theArray2, 0, (theList->listSize + 5) * sizeof (char *));        /* Copy the old entries.        */        Z2Memcpy (          theArray2, theList->nameList, theList->nameCount * sizeof (char *));        Z2Free (theList->nameList);        theList->nameList = (char **)theArray2;        theList->listSize += 5;        theArray2 = (char *)0;      }       nameLen = Z2Strlen (path);      VOLT_SET_FNCT_LINE (fnctLine)      status = VT_ERROR_MEMORY;      theList->nameList[theList->nameCount] = (char *)Z2Malloc (nameLen + 1, 0);      if (theList->nameList[theList->nameCount] == (char *)0)         break;           Z2Memcpy (theList->nameList[theList->nameCount], path, nameLen);      theList->nameList[theList->nameCount][nameLen] = 0;      theList->nameCount++;           NEXT_FILE :      if (path != (unsigned char *)0)      {        Z2Free (path);        path = (unsigned char *)0;      }            status = 0;      } /* while */      /* Free up any data allocated      */      if (path != (unsigned char *)0)        Z2Free (path);            if (newNameList != (VtFileNameList *)0)        VoltFileListFree (libCtx, &newNameList);            if (theArray2 != (char *)0)        Z2Free (theArray2);      if (status != 0)        break;      /* Success, return theList       */      *nameList = theList;      status = 0;        } while (0);      if (dir != (DIR *) 0 )      closedir (dir);          /* If success, we're done.    */    if (status == 0)      return (0);    /* If error, free up what we allocated and log the error.    */    if (theList != (VtFileNameList *)0)      VoltFileListFree (libCtx, &theList);    VOLT_LOG_ERROR (    (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,    "VoltGetFileListAlloc", (char *)0)    return (status);}#endif /* VOLT_OS == VOLT_MACOSX */

⌨️ 快捷键说明

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