//--------------------------------------------------------------------- bool __fastcall TPropertiesDialog::Execute(TRemoteProperties & Properties) { SetFileProperties(Properties); PageControl->ActivePage = CommonSheet; if (FAllowedChanges & cpGroup) ActiveControl = GroupComboBox; else if (FAllowedChanges & cpOwner) ActiveControl = OwnerComboBox; else if (FAllowedChanges & cpMode) ActiveControl = RightsFrame; else ActiveControl = CancelButton; ChecksumAlgEdit->Text = GUIConfiguration->ChecksumAlg; ResetChecksum(); UpdateControls(); bool Result = (ShowModal() == DefaultResult(this)); if (Result) { Properties = GetFileProperties(); } GUIConfiguration->ChecksumAlg = ChecksumAlgEdit->Text; return Result; }
/* This function maps to two in the AxxPac API: axxPacFindFirst and axxPacFindNext */ Err vfsDirEntryEnumerate(FileRef dirRef, UInt32 *dirEntryIteratorP, FileInfoType *infoP) { static axxPacFileInfo axxFileInfo; file_rec_t axxFileRec; Char symb[2] = "*\0"; Err ret; if (*dirEntryIteratorP == vfsIteratorStart) { if (GetFileProperties (dirRef,&axxFileRec)!=errNone) return vfsErrFileBadRef; /* Use the wildcar '*' after the dir name to use as a pattern to search */ StrCat(axxFileRec.name, symb); /* assumption: there is only one directory enumerated at a time */ ret = axxPacFindFirst(LibRef, axxFileRec.name, &axxFileInfo, FIND_FILES_ONLY); if (ret == 0) { infoP->attributes = axxFileInfo.attrib ; /* nameP will store the file name only if it is not null */ if (infoP->nameP != NULL) StrNCopy(infoP->nameP, axxFileInfo.name, min(256, infoP->nameBufLen)); } else { if (0 < ret) { *dirEntryIteratorP = vfsIteratorStop; return expErrEnumerationEmpty; } else { /* error should be mapped but... */ return vfsErrFileBadRef; } } ret = axxPacFindNext (LibRef, &axxFileInfo); if (0 < ret) *dirEntryIteratorP = vfsIteratorStop; else if (ret == 0) *dirEntryIteratorP = (Int32)&axxFileInfo; return errNone; } else { /* assumption: a call with vfsIteratorStart has been made before */ infoP->attributes = axxFileInfo.attrib ; /* nameP will store the file name only if it is not null */ if (infoP->nameP != NULL) StrNCopy(infoP->nameP, axxFileInfo.name, min(infoP->nameBufLen, 256)); ret=axxPacFindNext (LibRef, &axxFileInfo); if (0 < ret) *dirEntryIteratorP = vfsIteratorStop; else if ( ret == 0 ) *dirEntryIteratorP = (Int32)&axxFileInfo; return errNone; } }
Err vfsFileDBInfo(FileRef ref, Char *nameP, UInt16 *attributesP, UInt16 *versionP, UInt32 *crDateP, UInt32 *modDateP, UInt32 *bckUpDateP, UInt32 *modNumP, MemHandle *appInfoHP, MemHandle *sortInfoHP, UInt32 *typeP, UInt32 *creatorP, UInt16 *numRecordsP) { DatabaseHdrType DBHdr; file_rec_t axxFileRec; if (GetFileProperties (ref,&axxFileRec)!=errNone) return vfsErrBadData; if (axxFileRec.attrib & FA_SUBDIR) { return vfsErrBadData; } if (axxPacRead(LibRef, axxFileRec.fd, &DBHdr, sizeof(DatabaseHdrType)) != sizeof(DatabaseHdrType)) { return vfsErrBadData; } if (nameP != NULL) StrCopy(nameP, DBHdr.name); if (attributesP != NULL) *attributesP = DBHdr.attributes; if (versionP != NULL) *versionP=DBHdr.version; if (crDateP != NULL) *crDateP = DBHdr.creationDate; if (modDateP != NULL) *modDateP = DBHdr.modificationDate; if (bckUpDateP != NULL) *bckUpDateP = DBHdr.lastBackupDate; if (modNumP != NULL) *modNumP = DBHdr.modificationNumber; /* assumption: appInfoHP is NULL */ ASSERT_MSG("AIM5", appInfoHP == NULL); /* assumption: sortInfoHP is NULL */ ASSERT_MSG("AIM5", sortInfoHP == NULL); if (typeP != NULL) *typeP = DBHdr.type; if (creatorP != NULL) *creatorP = DBHdr.creator; if (numRecordsP != NULL) *numRecordsP = DBHdr.recordList.numRecords; return errNone; }
Err vfsFileDBGetRecord ( FileRef ref, UInt16 recIndex, MemHandle *recHP, UInt8 *recAttrP, UInt32 *uniqueIDP ) { UInt32 offset; UInt32 length; MemPtr mp; Char* buf; file_rec_t axxFileRec; Err err; if (GetFileProperties (ref,&axxFileRec)!=errNone) return dmErrNotRecordDB; if (currFileDesc != axxFileRec.fd) LoadOffsets(axxFileRec.fd); /*Get the record byte position withing the file */ mp = MemHandleLock(moff); ASSERT_MSG("AIM0", mp != 0); offset = ((UInt32*)mp)[recIndex * 2]; length = recIndex < nrec ? ((UInt32*)mp)[recIndex * 2 + 2] : axxFileRec.size; MemHandleUnlock(moff); if ( nrec < recIndex) { return dmErrIndexOutOfRange; } length -= offset; err=axxPacSeek(LibRef, axxFileRec.fd, offset, SEEK_SET); if (err==AXXPAC_ERR_FILE_CLOSED) { axxPacFD FileDesc; /*This happens when the axxPac has entered into sleep mode */ FileDesc = axxPacOpen(LibRef, axxFileRec.name,axxFileRec.mode); if (FileDesc<0) return dmErrNotRecordDB; /*The axxPac could have assigned a FileDesc different from before */ if (FileDesc!=axxFileRec.fd) { UpdateFileDesc (ref,FileDesc); axxFileRec.fd=FileDesc; } err=axxPacSeek(LibRef, FileDesc, offset, SEEK_SET); } *recHP = MemHandleNew(length); buf = MemHandleLock(*recHP); axxPacRead (LibRef, axxFileRec.fd, buf, length); MemHandleUnlock(*recHP); return errNone; }
Err vfsFileGetAttributes ( FileRef fileRef, UInt32 *attributesP ) { file_rec_t axxFileRec; if (GetFileProperties (fileRef,&axxFileRec)!=errNone) return vfsErrFileBadRef; *attributesP =axxFileRec.attrib; return errNone; }
Err vfsFileSize ( FileRef fileRef, UInt32 *fileSizeP ) { file_rec_t axxFileRec; if (GetFileProperties (fileRef,&axxFileRec)!=errNone) return vfsErrFileBadRef; *fileSizeP=axxFileRec.size; return errNone; }
Err vfsFileEOF (FileRef fileRef) { Int32 ret; Char buf; file_rec_t axxFileRec; if (GetFileProperties (fileRef,&axxFileRec)!=errNone) return expErrNotOpen; /* read one char to see if it is the end of the file */ ret = axxPacRead(LibRef, axxFileRec.fd, &buf, 1); if (ret < 0) return expErrNotOpen; if (ret == 0) return vfsErrFileEOF; ret = axxPacSeek(LibRef, axxFileRec.fd, -1, SEEK_CUR); return errNone; }
Err vfsFileRead (FileRef fileRef, UInt32 numBytes, void *bufP, UInt32 *numBytesReadP) { Int32 ret; file_rec_t axxFileRec; if (GetFileProperties (fileRef,&axxFileRec)!=errNone) return expErrNotOpen; ret = axxPacRead(LibRef, axxFileRec.fd, bufP, (Int32)numBytes); if (ret < 0) return expErrNotOpen; *numBytesReadP = ret; if (ret == 0) return vfsErrFileEOF; else return errNone; }
Err vfsFileClose (FileRef fileRef) { Err err = errNone; file_rec_t axxFileRec; if ( GetFileProperties ( fileRef, &axxFileRec ) != errNone ) return vfsErrFileBadRef; if ( ! ( axxFileRec.attrib & FA_SUBDIR ) ) { /* only files were actually opened */ err = axxPacClose( LibRef, axxFileRec.fd ); } if ( ( err == errNone ) || ( err==AXXPAC_ERR_FILE_CLOSED ) ) { /* Note: if it is a folder err will also be errNone since it was initialized to errNone */ RemoveFileRec( fileRef ); return errNone ; } else { return expErrNotOpen; } }
Err vfsFileWrite ( FileRef fileRef, UInt32 numBytes, void *dataP, UInt32 *numBytesWrittenP ) { Int32 ret; file_rec_t axxFileRec; if (GetFileProperties (fileRef,&axxFileRec)!=errNone) return expErrNotOpen; ret = axxPacWrite(LibRef, axxFileRec.fd, dataP, (Int32)numBytes); if (ret < 0) return expErrNotOpen; if (numBytesWrittenP != NULL) *numBytesWrittenP = ret; return errNone; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P r i n t K e y r i n g P r o p e r t i e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PrintKeyringProperties() prints properties associated with each key in the % keyring. % % The format of the PrintKeyringProperties method is: % % WizardBooleanType PrintKeyringProperties(const char *path, % BlobInfo *keyring_blob,ExceptionInfo *exception) % % A description of each parameter follows: % % o path: the keyring path. % % o blob_ibfo: list the key properties to this blob. % % o exception: Return any errors or warnings in this structure. % */ WizardExport WizardBooleanType PrintKeyringProperties(const char *path, BlobInfo *keyring_blob,ExceptionInfo *exception) { char *canonical_path, *hex, *keyring_rdf, message[WizardPathExtent]; const struct stat *properties; FileInfo *file_info; KeyringInfo keyring_info; ssize_t count; StringInfo *filetype, *id, *key, *magick, *nonce, *target; size_t length; WizardSizeType timestamp; WizardStatusType status; (void) LogWizardEvent(TraceEvent,GetWizardModule(),"..."); WizardAssert(KeymapDomain,exception != (ExceptionInfo *) NULL); file_info=AcquireFileInfo(path,KeyringFilename,ReadFileMode,exception); if (file_info == (FileInfo *) NULL) return(WizardTrue); keyring_rdf=AcquireString(" <keyring:Keyring rdf:about=\""); canonical_path=CanonicalXMLContent(GetFilePath(file_info),WizardFalse); (void) ConcatenateString(&keyring_rdf,canonical_path); (void) ConcatenateString(&keyring_rdf,"\">\n"); properties=GetFileProperties(file_info); (void) ConcatenateString(&keyring_rdf," <keyring:modify-date>"); (void) FormatWizardTime(properties->st_mtime,WizardPathExtent,message); (void) ConcatenateString(&keyring_rdf,message); (void) ConcatenateString(&keyring_rdf,"</keyring:modify-date>\n"); (void) ConcatenateString(&keyring_rdf," <keyring:create-date>"); (void) FormatWizardTime(properties->st_mtime,WizardPathExtent,message); (void) ConcatenateString(&keyring_rdf,message); (void) ConcatenateString(&keyring_rdf,"</keyring:create-date>\n"); (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>"); (void) FormatWizardTime(time((time_t *) NULL),WizardPathExtent,message); (void) ConcatenateString(&keyring_rdf,message); (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n"); (void) ConcatenateString(&keyring_rdf," </keyring:Keyring>\n"); length=strlen(keyring_rdf); count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf); keyring_rdf=DestroyString(keyring_rdf); if (count != (ssize_t) length) ThrowFileException(exception,FileError,GetFilePath(file_info)); magick=GetWizardMagick(WizardMagick,sizeof(WizardMagick)); target=CloneStringInfo(magick); status=ReadFileChunk(file_info,GetStringInfoDatum(target), GetStringInfoLength(target)); if ((status == WizardFalse) || (CompareStringInfo(target,magick) != 0)) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } magick=DestroyStringInfo(magick); target=DestroyStringInfo(target); filetype=GetWizardMagick((unsigned char *) KeyringFiletype, strlen(KeyringFiletype)); target=CloneStringInfo(filetype); status&=ReadFileChunk(file_info,GetStringInfoDatum(target), GetStringInfoLength(target)); if ((status == WizardFalse) || (CompareStringInfo(target,filetype) != 0)) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } filetype=DestroyStringInfo(filetype); target=DestroyStringInfo(target); length=0; (void) ResetWizardMemory(&keyring_info,0,sizeof(keyring_info)); while (ReadFile32Bits(file_info,&keyring_info.signature) != 0) { if (keyring_info.signature != WizardSignature) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } status&=ReadFile32Bits(file_info,&length); status&=ReadFile16Bits(file_info,&keyring_info.protocol_major); status&=ReadFile16Bits(file_info,&keyring_info.protocol_minor); if ((keyring_info.protocol_major == 1) && (keyring_info.protocol_minor == 0)) timestamp=(time_t) length; else status&=ReadFile64Bits(file_info,×tamp); keyring_info.timestamp=(time_t) timestamp; status&=ReadFile32Bits(file_info,&length); if (status == WizardFalse) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } id=AcquireStringInfo(length); status&=ReadFileChunk(file_info,GetStringInfoDatum(id), GetStringInfoLength(id)); status&=ReadFile32Bits(file_info,&length); if (status == WizardFalse) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } key=AcquireStringInfo(length); status&=ReadFileChunk(file_info,GetStringInfoDatum(key), GetStringInfoLength(key)); status&=ReadFile32Bits(file_info,&length); if (status == WizardFalse) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } nonce=AcquireStringInfo(length); status&=ReadFileChunk(file_info,GetStringInfoDatum(nonce), GetStringInfoLength(nonce)); keyring_rdf=AcquireString(" <keyring:Key rdf:about=\""); hex=StringInfoToHexString(id); (void) ConcatenateString(&keyring_rdf,hex); hex=DestroyString(hex); (void) ConcatenateString(&keyring_rdf,"\">\n"); (void) ConcatenateString(&keyring_rdf," <keyring:memberOf " "rdf:resource=\""); (void) ConcatenateString(&keyring_rdf,canonical_path); (void) ConcatenateString(&keyring_rdf,"\"/>\n"); (void) ConcatenateString(&keyring_rdf," <keyring:nonce>"); hex=StringInfoToHexString(nonce); (void) ConcatenateString(&keyring_rdf,hex); hex=DestroyString(hex); (void) ConcatenateString(&keyring_rdf,"</keyring:nonce>\n"); (void) ConcatenateString(&keyring_rdf," <keyring:timestamp>"); (void) FormatWizardTime(keyring_info.timestamp,WizardPathExtent,message); (void) ConcatenateString(&keyring_rdf,message); (void) ConcatenateString(&keyring_rdf,"</keyring:timestamp>\n"); (void) ConcatenateString(&keyring_rdf," <keyring:protocol>"); (void) FormatLocaleString(message,WizardPathExtent,"%u.%u", keyring_info.protocol_major,(unsigned int) keyring_info.protocol_minor); (void) ConcatenateString(&keyring_rdf,message); (void) ConcatenateString(&keyring_rdf,"</keyring:protocol>\n"); (void) ConcatenateString(&keyring_rdf," </keyring:Key>\n"); length=strlen(keyring_rdf); count=WriteBlob(keyring_blob,length,(unsigned char *) keyring_rdf); keyring_rdf=DestroyString(keyring_rdf); if (count != (ssize_t) length) ThrowFileException(exception,FileError,GetFilePath(file_info)); nonce=DestroyStringInfo(nonce); key=DestroyStringInfo(key); id=DestroyStringInfo(id); if (status == WizardFalse) { file_info=DestroyFileInfo(file_info,exception); (void) ThrowWizardException(exception,GetWizardModule(),KeyringError, "corrupt key ring file `%s'",GetFilePath(file_info)); return(WizardFalse); } } canonical_path=DestroyString(canonical_path); file_info=DestroyFileInfo(file_info,exception); return(WizardTrue); }