int main(int argc, const char * argv[]) {
  if( argc != 5 ){
    printf("Usage: %s UNCOMPRESSED COMPRESSED KEY\n", fileTail(argv[0]));
    printf("  UNCOMPRESSED: URI of uncompressed SQLite DB file.\n");
    printf("  COMPRESSED:   URI of new compressed DB with optional ?block_size=<block_size>\n");
    printf("  VFS_NAME:     Name of VFS to embed in database file.\n");
    printf("  KEY:          Encryption key in the form: x'<hex1><hex2>...<hex32>'\n");
    return EXIT_FAILURE;
  }

  int rc;

  // Convert encryption key string to hex blob.
  // This assumes that the key is in the form of x'<hex-string>'
  // You should, of course, implement proper error checking.
  const char *key = argv[4]+2;
  char *keyBytes = hexToBlob(key, (int)strlen(key)-1);

  ctx.pKey   = keyBytes;           // 32-bit encryption hex key
  ctx.nKeySz = kCCKeySizeAES256;   // key size in bytes
  ctx.nIvSz  = kCCBlockSizeAES128; // size of IV in bytes

  // You can use the VFS name to determine how you set up your xMethods,
  // so we pass the VFS name as a command line parameter as well.
  rc = cevfs_build(argv[1], argv[2], argv[3], &ctx, cevfsAutoDetect);
  return rc;
}
Beispiel #2
0
/*
** Open an vfstrace file handle.
*/
static int vfstraceOpen(
  sqlite3_vfs *pVfs,
  const char *zName,
  sqlite3_file *pFile,
  int flags,
  int *pOutFlags
){
  int rc;
  vfstrace_file *p = (vfstrace_file *)pFile;
  vfstrace_info *pInfo = (vfstrace_info*)pVfs->pAppData;
  sqlite3_vfs *pRoot = pInfo->pRootVfs;
  p->pInfo = pInfo;
  p->zFName = zName ? fileTail(zName) : "<temp>";
  p->pReal = (sqlite3_file *)&p[1];
  rc = pRoot->xOpen(pRoot, zName, p->pReal, flags, pOutFlags);
  vfstrace_printf(pInfo, "%s.xOpen(%s,flags=0x%x)",
                  pInfo->zVfsName, p->zFName, flags);
  if( p->pReal->pMethods ){
    sqlite3_io_methods *pNew = sqlite3_malloc( sizeof(*pNew) );
    const sqlite3_io_methods *pSub = p->pReal->pMethods;
    memset(pNew, 0, sizeof(*pNew));
    pNew->iVersion = pSub->iVersion;
    pNew->xClose = vfstraceClose;
    pNew->xRead = vfstraceRead;
    pNew->xWrite = vfstraceWrite;
    pNew->xTruncate = vfstraceTruncate;
    pNew->xSync = vfstraceSync;
    pNew->xFileSize = vfstraceFileSize;
    pNew->xLock = vfstraceLock;
    pNew->xUnlock = vfstraceUnlock;
    pNew->xCheckReservedLock = vfstraceCheckReservedLock;
    pNew->xFileControl = vfstraceFileControl;
    pNew->xSectorSize = vfstraceSectorSize;
    pNew->xDeviceCharacteristics = vfstraceDeviceCharacteristics;
    if( pNew->iVersion>=2 ){
      pNew->xShmMap = pSub->xShmMap ? vfstraceShmMap : 0;
      pNew->xShmLock = pSub->xShmLock ? vfstraceShmLock : 0;
      pNew->xShmBarrier = pSub->xShmBarrier ? vfstraceShmBarrier : 0;
      pNew->xShmUnmap = pSub->xShmUnmap ? vfstraceShmUnmap : 0;
    }
    pFile->pMethods = pNew;
  }
  vfstrace_print_errcode(pInfo, " -> %s", rc);
  if( pOutFlags ){
    vfstrace_printf(pInfo, ", outFlags=0x%x\n", *pOutFlags);
  }else{
    vfstrace_printf(pInfo, "\n");
  }
  return rc;
}
Beispiel #3
0
/*
 * Returns TRUE if user left off file extension, allowing default.
 * Note that the name is misleading if multiple dots are allowed.
 * not_pgp_extension or something would be better.
 */
PGPBoolean noExtension( struct pgpfileBones *filebPtr, char *filename )
{
#ifdef MULTIPLE_DOTS  /* filename can have more than one dot */
    if (hasExtension(filename, filebPtr->ASC_EXTENSION) ||
            hasExtension(filename, filebPtr->PGP_EXTENSION) ||
            hasExtension(filename, filebPtr->PKR_EXTENSION) ||
            hasExtension(filename, filebPtr->SKR_EXTENSION) ||
            hasExtension(filename, filebPtr->SIG_EXTENSION) ||
            isTempFile(filebPtr, filename))
        return FALSE;
    else
        return TRUE;
#else
    filename = fileTail(filename);

    return strrchr(filename, '.') == NULL;
#endif
} /* no_extension */