8 #if defined( __UNIX__ ) && defined( __linux__ )
19 #if defined( INC_ALL )
73 #if defined( __MVS__ ) && defined( DDNAME_IO )
74 #define CONFIG_NO_STDIO
79 #if defined( __MVS__ ) && defined( DDNAME_IO )
80 #pragma convlit( suspend )
81 #define MODE_READ "rb,byteseek"
82 #define MODE_WRITE "wb,byteseek,recfm=*"
83 #define MODE_READWRITE "rb+,byteseek,recfm=*"
84 #pragma convlit( resume )
85 #elif defined( EBCDIC_CHARS )
86 #pragma convlit( suspend )
87 #define MODE_READ "rb"
88 #define MODE_WRITE "wb"
89 #define MODE_READWRITE "rb+"
90 #pragma convlit( resume )
92 #define MODE_READ "rb"
93 #define MODE_WRITE "wb"
94 #define MODE_READWRITE "rb+"
117 const int partialPathLen = strlen( path );
120 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
129 fileNameLen == 0 ) );
139 if( partialPathLen + 12 > pathMaxLen )
141 memcpy( path + partialPathLen,
"randseed.dat", 12 );
142 *pathLen = partialPathLen + 12;
149 if( partialPathLen + fileNameLen + 4 > pathMaxLen )
151 memcpy( path + partialPathLen, fileName, fileNameLen );
152 memcpy( path + partialPathLen + fileNameLen,
".p15", 4 );
153 *pathLen = partialPathLen + fileNameLen + 4;
160 #pragma convlit( suspend )
163 static
int appendFilenameEBCDIC(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
166 IN_BUFFER( fileNameLen )
const char *fileName,
171 const int partialPathLen = strlen( path );
174 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
183 fileNameLen == 0 ) );
193 if( partialPathLen + 12 > pathMaxLen )
195 memcpy( path + partialPathLen,
"randseed.dat", 12 );
196 *pathLen = partialPathLen + 12;
203 if( partialPathLen + fileNameLen + 4 > pathMaxLen )
205 memcpy( path + partialPathLen, fileName, fileNameLen );
206 memcpy( path + partialPathLen + fileNameLen,
".p15", 4 );
207 *pathLen = partialPathLen + fileNameLen + 4;
212 #pragma convlit( resume )
222 #if defined( __AMX__ )
230 static const int modes[] = {
231 FJ_O_RDONLY, FJ_O_RDONLY,
232 FJ_O_WRONLY | FJ_O_CREAT | FJ_O_NOSHAREANY,
233 FJ_O_RDWR | FJ_O_NOSHAREWR
242 memset( stream, 0,
sizeof(
STREAM ) );
254 stream->fd = fjopen( fileName, openMode, ( openMode & FJ_O_CREAT ) ? \
255 FJ_S_IREAD | FJ_S_IWRITE : 0 );
258 const int errNo = fjfserrno();
260 return( ( errNo == FJ_EACCES || errNo == FJ_ESHARE ) ? \
262 ( errNo == FJ_ENOENT ) ? \
277 fjclose( stream->fd );
295 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
303 if( ( byteCount = fjread( stream->fd, buffer, length ) ) < 0 )
305 *bytesRead = byteCount;
323 if( ( bytesWritten = fjwrite( stream->fd, buffer, length ) ) < 0 || \
324 bytesWritten != length )
338 fjflush( stream->fd );
351 if( fjlseek( stream->fd, position, FJ_SEEK_SET ) < 0 )
361 struct fjxstat fileInfo;
365 if( fjstat( fileName, &fileInfo ) < 0 )
368 return( ( fileInfo->_xxx ) ?
TRUE :
FALSE );
375 static void eraseFile(
const STREAM *stream,
long position,
long length )
389 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
390 int bytesToWrite =
min( length, BUFSIZ * 2 );
397 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
399 if( fjwrite( stream->fd, buffer, bytesToWrite ) < 0 )
401 length -= bytesToWrite;
404 fjchsize( stream->fd, position );
408 void fileClearToEOF(
const STREAM *stream )
410 struct fjxstat fileInfo;
418 if( fjstat( fileName, &fileInfo ) < 0 )
420 length = fileInfo._xxx;
421 if( ( position = fjtell( stream->fd ) ) < 0 )
426 eraseFile( stream, position, length );
430 void fileErase(
IN_STRING const char *fileName )
433 struct fjxstat fileInfo;
440 status = sFileOpen( &stream, fileName,
451 fjstat( fileName, &fileInfo );
452 eraseFile( &stream, 0, fileInfo._xxx );
455 fjfattr( stream.fd, FJ_DA_NORMAL );
458 sFileClose( &stream );
459 fjunlink( fileName );
465 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
468 IN_BUFFER( fileNameLen )
const char *fileName,
474 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
475 assert(
isReadPtr( fileName, fileNameLen ) );
482 fileNameLen == 0 ) );
489 strlcpy_s( path, pathMaxLen,
"\\cryptlib\\" );
496 if( fjmkdir( path ) < 0 )
501 return( appendFilename( path, pathMaxLen, pathLen, fileName,
502 fileNameLen, option ) );
511 #elif defined( __UCOSII__ )
525 const char *openMode;
533 memset( stream, 0,
sizeof(
STREAM ) );
541 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
545 stream->pFile = FS_FOpen( fileName, openMode );
546 if( stream->pFile == NULL )
548 const FS_i16 errNo = FS_FError();
554 return( ( errNo == FS_ERR_DISKFULL ) ? \
555 CRYPT_ERROR_OVEWFLOW : \
556 ( errNo == FS_ERR_READONLY ) ? \
571 FS_FClose( stream->pFile );
581 OUT_BUFFER( length, *bytesRead )
void *buffer,
589 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
597 if( ( byteCount = FS_Read( stream->pFile, buffer, length ) ) < 0 )
599 *bytesRead = byteCount;
617 if( ( bytesWritten = FS_Write( stream->pFile, buffer, length ) ) < 0 || \
618 bytesWritten != length )
648 if( FS_FSeek( stream->pFile, position, FS_SEEK_SET ) < 0 )
662 if( ( fileAttr = FS_GetFileAttributes( fileName ) ) == 0xFF )
665 return( ( fileAttr & FS_ATTR_READONLY ) ?
TRUE :
FALSE );
672 static void eraseFile(
const STREAM *stream,
long position,
long length )
686 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
687 int bytesToWrite =
min( length, BUFSIZ * 2 );
694 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
696 if( FS_Write( stream->pFile, buffer, bytesToWrite ) < 0 )
698 length -= bytesToWrite;
701 fjchsize( stream->pFile, position );
705 void fileClearToEOF(
const STREAM *stream )
714 if( ( length = FS_GetFileSize( fileName ) ) < 0 )
716 if( ( position = FS_FTell( stream->pFile ) ) < 0 )
721 eraseFile( stream, position, length );
725 void fileErase(
IN_STRING const char *fileName )
732 if( ( length = FS_GetFileSize( fileName ) ) < 0 )
737 status = sFileOpen( &stream, fileName,
748 eraseFile( &stream, 0, length );
751 sFileClose( &stream );
752 FS_SetFileAttributes( stream.pFile, FS_ATTR_ARCHIVE );
753 FS_SetFileTime( stream.pFile, 0 );
754 FS_Remove( fileName );
760 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
763 IN_BUFFER( fileNameLen )
const char *fileName,
769 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
770 assert(
isReadPtr( fileName, fileNameLen ) );
777 fileNameLen == 0 ) );
784 strlcpy_s( path, pathMaxLen,
"\\cryptlib\\" );
795 if( ( dirInfo = FS_OpenDir( path ) ) != NULL )
796 FSCloseDir( dirInfo );
800 if( FS_MkDir( path ) < 0 )
806 return( appendFilename( path, pathMaxLen, pathLen, fileName,
807 fileNameLen, option ) );
818 #elif defined( __ITRON__ )
832 memset( stream, 0,
sizeof(
STREAM ) );
839 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
863 OUT_BUFFER( length, *bytesRead )
void *buffer,
869 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
931 static void eraseFile(
const STREAM *stream,
long position,
long length )
945 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
946 int bytesToWrite =
min( length, BUFSIZ * 2 );
953 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
954 if( fwrite( buffer, 1, bytesToWrite, stream->
filePtr ) == 0 )
956 length -= bytesToWrite;
963 chsize( fileno( stream->
filePtr ), position );
966 struct ftime fileTime;
968 memset( &fileTime, 0,
sizeof(
struct ftime ) );
969 setftime( fileno( stream->
filePtr ), &fileTime );
974 void fileClearToEOF(
const STREAM *stream )
983 position = ftell( stream->
filePtr );
987 eraseFile( stream, position, length );
991 void fileErase(
IN_STRING const char *fileName )
1000 status = sFileOpen( &stream, fileName,
1012 length = ( int ) ftell( stream.
filePtr );
1014 eraseFile( stream, 0, length );
1018 sFileClose( &stream );
1027 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
1030 IN_BUFFER( fileNameLen )
const char *fileName,
1036 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
1037 assert(
isReadPtr( fileName, fileNameLen ) );
1044 fileNameLen == 0 ) );
1050 return( appendFilename( path, pathMaxLen, pathLen, fileName,
1051 fileNameLen, option ) );
1060 #elif defined( __MAC__ )
1064 static void CStringToPString(
const char *cstring, StringPtr pstring )
1066 short len =
min( strlen( cstring ), 255 );
1068 memmove( pstring + 1, cstring, len );
1087 memset( stream, 0,
sizeof(
STREAM ) );
1092 CStringToPString( fileName, pFileName );
1093 err = FSMakeFSSpec( 0, 0, pFileName, &stream->fsspec );
1094 if( err == dirNFErr || err == nsvErr )
1099 if( err != noErr && err != fnfErr )
1105 if( mode & FILE_FLAG_WRITE )
1113 err = FSpCreate( &stream->fsspec, 0x3F3F3F3F ,
'CLib',
1115 if( err == wPrErr || err == vLckdErr || err == afpAccessDenied )
1117 if( err != noErr && err != dupFNErr && err != afpObjectTypeErr )
1121 err = FSpOpenDF( &stream->fsspec, mode & FILE_FLAG_RW_MASK,
1123 if( err == nsvErr || err == dirNFErr || err == fnfErr )
1125 if( err == opWrErr || err == permErr || err == afpAccessDenied )
1141 FSClose( stream->refNum );
1151 OUT_BUFFER( length, *bytesRead )
void *buffer,
1159 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
1167 if( FSRead( stream->refNum, &bytesRead, buffer ) != noErr )
1169 *bytesRead = byteCount;
1179 long bytesWritten =
length;
1187 if( FSWrite( stream->refNum, &bytesWritten, buffer ) != noErr || \
1188 (
int ) bytesWritten != length )
1198 FileParam paramBlock;
1204 paramBlock.ioCompletion = NULL;
1205 paramBlock.ioFRefNum = stream->refNum;
1206 PBFlushFileSync( (
union ParamBlockRec * ) ¶mBlock );
1220 if( SetFPos( stream->refNum, fsFromStart, position ) != noErr )
1237 CStringToPString( fileName, pFileName );
1239 err = FSMakeFSSpec( 0, 0, pFileName, &fsspec );
1241 err = FSpOpenDF( &fsspec, fsRdWrPerm, &refnum );
1245 if ( err == opWrErr || err == permErr || err == afpAccessDenied )
1255 static void eraseFile(
const STREAM *stream,
long position,
long length )
1269 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
1270 int bytesToWrite =
min( length, BUFSIZ * 2 );
1277 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
1278 if( FSWrite( stream->refNum, &bytesWritten, buffer ) != noErr )
1280 length -= bytesToWrite;
1283 SetFPos( stream->refNum, fsFromStart, position );
1284 SetEOF( stream->refNum, position );
1288 void fileClearToEOF(
const STREAM *stream )
1297 if( GetFPos( stream->refNum, &position ) != noErr || \
1298 GetEOF( stream->refNum, &eof ) != noErr )
1303 eraseFile( stream, position, length );
1307 void fileErase(
IN_STRING const char *fileName )
1316 status = sFileOpen( &stream, fileName,
1327 SetFPos( stream.refNum, fsFromStart, 0 );
1328 GetEOF( stream.refNum, &length );
1329 eraseFile( stream, position, length );
1332 sFileClose( &stream );
1333 FSpDelete( stream.fsspec );
1339 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
1342 IN_BUFFER( fileNameLen )
const char *fileName,
1348 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
1349 assert(
isReadPtr( fileName, fileNameLen ) );
1356 fileNameLen == 0 ) );
1364 return( appendFilename( path, pathMaxLen, pathLen, fileName,
1365 fileNameLen, option ) );
1374 #elif defined( CONFIG_NO_STDIO )
1376 #if defined( __MVS__ ) || defined( __VMCMS__ ) || \
1377 defined( __IBM4758__ ) || defined( __TESTIO__ )
1403 #elif defined( EBCDIC_CHARS )
1404 #pragma convlit( suspend )
1407 #pragma convlit( resume )
1408 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
1413 #if defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1414 const char *openMode;
1425 memset( stream, 0,
sizeof(
STREAM ) );
1431 #if defined( __IBM4758__ )
1437 if( strlen( fileName ) > 8 )
1446 status = sccGetPPDLen( (
char * ) fileName, &length );
1447 if( status != PPDGood )
1453 if( ( stream->buffer =
clAlloc(
"sFileOpen", length ) ) == NULL )
1455 stream->bufSize = stream->bufEnd =
length;
1456 stream->isIOStream =
TRUE;
1460 status = sccGetPPD( (
char * ) fileName, stream->buffer, length );
1468 status = sccQueryPPDSpace( &length, useBBRAM ? PPD_BBRAM : PPD_FLASH );
1473 if( ( stream->buffer =
clAlloc(
"sFileOpen",
1477 stream->isSensitive = useBBRAM;
1480 #elif defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1487 strlcpy_s( stream->name, MAX_PATH_LENGTH, fileName );
1489 fileName = bufferToEbcdic( fileNameBuffer, fileName );
1493 if( mode & FILE_FLAG_READ )
1496 #if defined( __MVS__ ) || defined( __VMCMS__ )
1498 char fileBuffer[ MAX_PATH_LENGTH + 8 ];
1503 filePtr = fopen( fileName, openMode );
1504 if( filePtr == NULL )
1511 #if defined( __MVS__ ) || defined( __VMCMS__ )
1515 return( ( errno == ENOENT || errno == 67 || errno == 49 ) ? \
1517 #elif defined( __WIN32__ )
1518 return( ( GetLastError() == ERROR_FILE_NOT_FOUND ) ? \
1521 return( errno == ENOENT ) ? \
1525 #if defined( __MVS__ ) || defined( __VMCMS__ )
1526 status = fldata( filePtr, fileBuffer, &fileData );
1530 return( CRYPT_ERROR_OPEN );
1532 length = fileData.__maxreclen;
1535 length = ftell( filePtr );
1541 return( CRYPT_ERROR_OPEN );
1552 if( ( stream->buffer =
clAlloc(
"sFileOpen", allocSize ) ) == NULL )
1557 stream->bufSize = allocSize;
1559 status = fread( stream->buffer, length, 1, filePtr );
1563 clFree(
"sFileOpen", stream->buffer );
1570 if( ( stream->buffer =
clAlloc(
"sFileOpen",
1577 #error Need to add mechanism to connect stream to backing store
1578 return( CRYPT_ERROR_OPEN );
1589 #if defined( __IBM4758__ ) || defined( __MVS__ ) || \
1590 defined( __VMCMS__ ) || defined( __TESTIO__ )
1592 zeroise( stream->buffer, stream->bufSize );
1593 clFree(
"sFileClose", stream->buffer );
1598 #error Need to add mechanism to disconnect stream from backing store
1609 OUT_BUFFER( length, *bytesRead )
void *buffer,
1615 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
1651 #if defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1660 #if defined( __IBM4758__ )
1662 if( sccSavePPD( stream->name, stream->buffer, stream->bufEnd,
1663 ( stream->isSensitive ? PPD_BBRAM : PPD_FLASH ) | PPD_TRIPLE ) != PPDGood )
1666 #elif defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1673 char formatBuffer[ 64 + 8 ];
1674 sprintf_s( formatBuffer, 64,
"wb,recfm=F,lrecl=%d,noseek",
1676 filePtr = fopen( stream->name, formatBuffer );
1679 if( filePtr == NULL )
1681 count = fwrite( stream->buffer, stream->bufEnd, 1, filePtr );
1685 #error Need to add mechanism to commit data to backing store
1699 #if defined( __IBM4758__ ) || defined( __MVS__ ) || \
1700 defined( __VMCMS__ ) || defined( __TESTIO__ )
1706 #error Need to add mechanism to perform virtual seek on backing store
1718 #if defined( __IBM4758__ ) || defined( __MVS__ ) || \
1719 defined( __VMCMS__ ) || defined( __TESTIO__ )
1726 #error Need to add mechanism to determine readability of data in backing store
1736 void fileClearToEOF(
const STREAM *stream )
1742 #if defined( __IBM4758__ ) || defined( __MVS__ ) || \
1743 defined( __VMCMS__ ) || defined( __TESTIO__ )
1748 #error Need to add clear-to-EOF function for data in backing store
1753 void fileErase(
IN_STRING const char *fileName )
1755 #if defined( __IBM4758__ )
1756 sccDeletePPD( (
char * ) fileName );
1757 #elif defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1760 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
1766 #if defined( __MVS__ ) && defined( DDNAME_IO )
1770 fileName = bufferToEbcdic( fileNameBuffer, fileName );
1773 #elif defined( __MVS__ ) || defined( __VMCMS__ )
1776 fileName = bufferToEbcdic( fileNameBuffer, fileName );
1777 #pragma convlit( suspend )
1780 if( filePtr != NULL )
1783 char fileBuffer[ MAX_PATH_LENGTH + 8 ];
1785 if( fldata( filePtr, fileBuffer, &fileData ) == 0 )
1786 length = fileData.__maxreclen;
1789 #pragma convlit( resume )
1794 if( filePtr != NULL )
1797 length = ( int ) ftell( filePtr );
1814 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
1815 fwrite( buffer, 1, length, filePtr );
1817 if( filePtr != NULL )
1824 #error Need to add erase function for data in backing store
1831 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
1834 IN_BUFFER( fileNameLen )
const char *fileName,
1840 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
1841 assert(
isReadPtr( fileName, fileNameLen ) );
1848 fileNameLen == 0 ) );
1854 #if defined( __IBM4758__ )
1858 strlcpy_s( path, pathMaxLen,
"RANDSEED" );
1861 strlcpy_s( path, pathMaxLen, fileName );
1863 #elif defined( __MVS__ ) || defined( __VMCMS__ ) || defined( __TESTIO__ )
1864 #if defined( DDNAME_IO )
1868 strlcpy_s( path, pathMaxLen,
"//RANDSEED" );
1871 strlcpy_s( path, pathMaxLen,
"//CRYPTLIB." );
1872 strlcat_s( path, pathMaxLen, fileName );
1877 return( appendFilename( path, pathMaxLen, pathLen, fileName,
1878 fileNameLen, option ) );
1881 #error Need to add function to build path to config data in backing store
1883 return( CRYPT_ERROR_OPEN );
1893 #elif defined( __PALMOS__ )
1895 #include <FeatureMgr.h>
1901 static BOOLEAN checkVFSMgr(
void )
1903 uint32_t vfsMgrVersion;
1905 return( ( FtrGet( sysFileCVFSMgr, vfsFtrIDVersion,
1906 &vfsMgrVersion ) == errNone ) ?
TRUE :
FALSE );
1915 static const int modes[] = {
1916 vfsModeRead, vfsModeRead,
1917 vfsModeCreate | vfsModeExclusive | vfsModeWrite,
1920 uint32_t volIterator = vfsIteratorStart;
1921 uint16_t volRefNum, openMode;
1930 memset( stream, 0,
sizeof(
STREAM ) );
1932 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
1938 if( !checkVFSMgr() )
1939 return( CRYPT_ERROR_OPEN );
1940 if( VFSVolumeEnumerate( &volRefNum, &volIterator ) != errNone )
1941 return( CRYPT_ERROR_OPEN );
1945 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
1949 err = VFSFileOpen( volRefNum, fileName, openMode, &stream->fileRef );
1950 if( err == vfsErrFilePermissionDenied || err == vfsErrIsADirectory || \
1951 err == vfsErrVolumeFull )
1953 if( err == vfsErrFileNotFound )
1955 if( err != errNone )
1956 return( CRYPT_ERROR_OPEN );
1969 VFSFileClose( stream->fileRef );
1979 OUT_BUFFER( length, *bytesRead )
void *buffer,
1987 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
1995 if( VFSFileRead( stream->fileRef, length, buffer,
1996 &byteCount ) != errNone )
1998 *bytesRead = byteCount;
2008 uint32_t bytesWritten;
2016 if( VFSFileWrite( stream->fileRef, length, buffer,
2017 &bytesWritten ) != errNone || \
2018 bytesWritten != length )
2052 if( VFSFileSeek( stream->fileRef, vfsOriginBeginning,
2053 position ) != errNone )
2064 uint32_t volIterator = vfsIteratorStart;
2070 if( VFSVolumeEnumerate( &volRefNum, &volIterator ) != errNone )
2072 err = VFSFileOpen( volRefNum, fileName, vfsModeRead, &fileRef );
2073 if( err == errNone )
2074 VFSFileClose( fileRef );
2076 return( ( err == vfsErrFilePermissionDenied ) ?
TRUE :
FALSE );
2083 static void eraseFile(
const STREAM *stream,
long position,
long length )
2097 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
2098 uint32_t bytesWritten;
2099 int bytesToWrite =
min( length, BUFSIZ * 2 );
2106 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
2108 if( VFSFileWrite( stream->fileRef, bytesToWrite, buffer,
2109 &bytesWritten ) != errNone )
2111 length -= bytesToWrite;
2114 VFSFileResize( stream->fileRef, position );
2118 void fileClearToEOF(
const STREAM *stream )
2127 if( VFSFileSize( stream->fileRef, &length ) != errNone || \
2128 VFSFileTell( stream->fileRef, &position ) != errNone );
2133 eraseFile( stream, position, length );
2137 void fileErase(
IN_STRING const char *fileName )
2140 uint32_t volIterator = vfsIteratorStart,
length;
2148 if( VFSVolumeEnumerate( &volRefNum, &volIterator ) != errNone )
2150 status = sFileOpen( &stream, fileName,
2151 FILE_FLAG_READ | FILE_FLAG_WRITE |
2161 VFSFileSize( stream.fileRef, &length );
2162 eraseFile( &stream, 0, length );
2165 VFSFileSetAttributes( stream.fileRef, 0 );
2166 VFSFileSetDate( stream.fileRef, vfsFileDateAccessed, 0 );
2167 VFSFileSetDate( stream.fileRef, vfsFileDateCreated, 0 );
2168 VFSFileSetDate( stream.fileRef, vfsFileDateModified, 0 );
2171 sFileClose( &stream );
2172 VFSFileDelete( volRefNum, fileName );
2178 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
2181 IN_BUFFER( fileNameLen )
const char *fileName,
2187 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
2188 assert(
isReadPtr( fileName, fileNameLen ) );
2195 fileNameLen == 0 ) );
2201 if( !checkVFSMgr() )
2205 strlcpy_s( path, pathMaxLen,
"/PALM/cryptlib/" );
2212 uint32_t volIterator = vfsIteratorStart;
2215 if( VFSVolumeEnumerate( &volRefNum, &volIterator ) != errNone )
2216 return( CRYPT_ERROR_OPEN );
2217 if( VFSFileOpen( volRefNum, path, vfsModeRead, &fileRef ) == errNone )
2218 VFSFileClose( fileRef );
2222 if( VFSDirCreate( volRefNum, path ) != errNone )
2223 return( CRYPT_ERROR_OPEN );
2228 return( appendFilename( path, pathMaxLen, pathLen, fileName,
2229 fileNameLen, option ) );
2238 #elif defined( __FileX__ )
2249 static FX_MEDIA *media = NULL;
2252 int setMedia( FX_MEDIA *mediaPtr )
2254 assert(
isWritePtr( mediaPtr,
sizeof( FX_MEDIA ) ) );
2268 static const int modes[] = { FX_OPEN_FOR_READ, FX_OPEN_FOR_READ,
2270 FX_OPEN_FOR_READ | FX_OPEN_FOR_WRITE };
2277 REQUIRE( mode != 0 );
2280 memset( stream, 0,
sizeof(
STREAM ) );
2282 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
2292 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_WRITE )
2294 if( fx_file_create( media, fileName ) != FX_SUCCESS )
2295 return( CRYPT_ERROR_OPEN );
2296 if( fx_file_open( media, &stream->filePtr, fileName,
2297 FX_OPEN_FOR_WRITE ) != FX_SUCCESS )
2299 fx_file_delete( media, fileName );
2300 return( CRYPT_ERROR_OPEN );
2305 openStatus = fx_file_open( media, &stream->filePtr, fileName, openMode );
2306 if( openStatus != FX_SUCCESS )
2309 ( openStatus == FX_ACCESS_ERROR || \
2313 stream->position = 0;
2326 fx_file_close( stream->filePtr );
2336 OUT_BUFFER( length, *bytesRead )
void *buffer,
2344 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
2352 if( ( fx_file_read( stream->filePtr, buffer, length, \
2353 &byteCount ) != FX_SUCCESS ) || \
2354 byteCount != length )
2356 stream->position += byteCount;
2357 *bytesRead = byteCount;
2373 if( fx_file_write( stream->filePtr, buffer, length ) != FX_SUCCESS )
2375 stream->position +=
length;
2389 if( fx_media_flush( media ) != FX_SUCCESS )
2405 if( fx_file_seek( stream->filePtr, position ) != FX_SUCCESS )
2421 if( fx_file_attribute_read( media, fileName, &attributes ) != FX_SUCCESS )
2423 return( ( attributes & ( FX_READ_ONLY | FX_HIDDEN | FX_SYSTEM ) ) ? \
2431 static void eraseFile( FX_FILE *filePtr,
long position,
long length )
2444 BYTE buffer[ 1024 + 8 ];
2445 int bytesToWrite =
min( length, 1024 );
2452 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
2454 if( fx_file_write( filePtr, buffer, bytesToWrite ) != FX_SUCCESS )
2456 length -= bytesToWrite;
2463 fx_filetruncate_release( filePtr, position );
2467 void fileClearToEOF(
const STREAM *stream )
2482 fx_filetruncate_release( stream->
filePtr, stream->position );
2486 void fileErase(
IN_STRING const char *fileName )
2495 status = sFileOpen( &stream, fileName,
2496 FILE_FLAG_READ | FILE_FLAG_WRITE | \
2510 for( length = 0; length < 50000; length++ )
2512 BYTE buffer[ 1 + 8 ];
2515 if( ( fx_file_read( stream->
filePtr, buffer, 1, \
2516 &bytesRead ) != FX_SUCCESS ) || bytesRead != 1 )
2519 fx_file_seek( stream->
filePtr, 0 );
2521 eraseFile( &stream, 0, length );
2524 fx_file_attribute_set( stream->
filePtr, FJ_DA_NORMAL );
2527 sFileClose( &stream );
2528 fx_file_delete( media, fileName );
2534 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
2537 IN_BUFFER( fileNameLen )
const char *fileName,
2543 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
2544 assert(
isReadPtr( fileName, fileNameLen ) );
2551 fileNameLen == 0 ) );
2557 strlcpy_s( path, pathMaxLen,
"/cryptlib/" );
2562 fx_directory_name_test( path ) != FX_SUCCESS )
2565 if( fx_directory_create( media, path ) != FX_SUCCESS )
2566 return( CRYPT_ERROR_OPEN );
2570 return( appendFilename( path, pathMaxLen, pathLen, fileName,
2571 fileNameLen, option ) );
2580 #elif defined( __BEOS__ ) || defined( __ECOS__ ) || defined( __MVS__ ) || \
2581 defined( __RTEMS__ ) || defined( __SYMBIAN32__ ) || \
2582 defined( __TANDEM_NSK__ ) || defined( __TANDEM_OSS__ ) || \
2592 #if defined( __TANDEM_NSK__ ) || defined( __TANDEM_OSS__ )
2594 int ftruncate(
int fd, off_t length )
2603 #define O_NOFOLLOW 0
2611 const int flags,
const int openMode )
2634 for( count = 0; count < 4; count++ )
2636 fd = open( fileName, flags, openMode | O_NOFOLLOW );
2641 if( flags & O_CREAT )
2642 return( CRYPT_ERROR_OPEN );
2646 return( ( access( fileName, 0 ) < 0 ) ? \
2660 return( CRYPT_ERROR_OPEN );
2676 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
2678 #if !defined( USE_EMBEDDED_OS ) && defined( USE_FCNTL_LOCKING )
2679 struct flock flockInfo;
2688 memset( stream, 0,
sizeof(
STREAM ) );
2690 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
2695 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
2699 fileName = bufferToEbcdic( fileNameBuffer, fileName );
2724 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_WRITE )
2726 struct stat lstatInfo;
2732 if( lstat( fileName, &lstatInfo ) < 0 )
2736 if( errno != ENOENT )
2737 return( CRYPT_ERROR_OPEN );
2746 status = openFile( stream, fileName,
2747 O_CREAT | O_EXCL | O_RDWR | extraOpenFlags,
2754 struct stat fstatInfo;
2758 if( !S_ISREG( lstatInfo.st_mode ) || lstatInfo.st_nlink != 1 )
2759 return( CRYPT_ERROR_OPEN );
2762 status = openFile( stream, fileName, O_RDWR | extraOpenFlags, 0 );
2768 if( fstat( stream->fd, &fstatInfo ) < 0 || \
2769 lstatInfo.st_mode != fstatInfo.st_mode || \
2770 lstatInfo.st_ino != fstatInfo.st_ino || \
2771 lstatInfo.st_dev != fstatInfo.st_dev || \
2772 lstatInfo.st_nlink != fstatInfo.st_nlink )
2774 close( stream->fd );
2775 return( CRYPT_ERROR_OPEN );
2791 if( !S_ISREG( fstatInfo.st_mode ) || fstatInfo.st_nlink != 1 )
2793 close( stream->fd );
2794 return( CRYPT_ERROR_OPEN );
2798 if( ftruncate( stream->fd, 0 ) < 0 )
2800 close( stream->fd );
2801 return( CRYPT_ERROR_OPEN );
2807 static const int modes[] = { O_RDONLY, O_RDONLY, O_WRONLY, O_RDWR };
2811 status = openFile( stream, fileName,
2812 modes[ mode & FILE_FLAG_RW_MASK ] | extraOpenFlags,
2820 fchmod( stream->fd, 0600 );
2885 #ifndef USE_EMBEDDED_OS
2886 #ifndef USE_FCNTL_LOCKING
2888 LOCK_EX | LOCK_NB : LOCK_SH | LOCK_NB ) < 0 && \
2889 errno == EWOULDBLOCK )
2891 close( stream->fd );
2895 memset( &flockInfo, 0,
sizeof(
struct flock ) );
2899 flockInfo.l_start = flockInfo.l_len = 0;
2900 if( fcntl( stream->fd, F_SETLK, &flockInfo ) < 0 && \
2901 ( errno == EACCES || errno == EDEADLK ) )
2912 close( stream->fd );
2934 #if !defined( USE_EMBEDDED_OS ) && !defined( USE_FCNTL_LOCKING )
2935 flock( stream->fd, LOCK_UN );
2960 if( close( stream->fd ) < 0 )
2974 OUT_BUFFER( length, *bytesRead )
void *buffer,
2982 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
2990 if( ( byteCount = read( stream->fd, buffer, length ) ) < 0 )
2992 *bytesRead = byteCount;
3008 if( write( stream->fd, buffer, length ) != length )
3051 return( ( fsync( stream->fd ) == 0 ) ? \
3065 if( lseek( stream->fd, position,
SEEK_SET ) == ( off_t ) -1 )
3076 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
3080 fileName = bufferToEbcdic( fileNameBuffer, fileName );
3084 if( access( fileName,
W_OK ) < 0 && errno != ENOENT )
3095 static
void eraseFile(
const STREAM *stream,
long position,
long length )
3114 BYTE buffer[ 1024 + 8 ];
3115 const int bytesToWrite =
min( length, 1024 );
3122 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
3123 if( write( stream->fd, buffer, bytesToWrite ) <= bytesToWrite )
3125 length -= bytesToWrite;
3127 fsync( stream->fd );
3132 {
int x = ftruncate( stream->fd, position ); }
3134 ( void ) ftruncate( stream->fd, position );
3139 void fileClearToEOF(
const STREAM *stream )
3141 struct stat fstatInfo;
3149 if( fstat( stream->fd, &fstatInfo ) < 0 )
3151 position = lseek( stream->fd, 0,
SEEK_CUR );
3152 length = fstatInfo.st_size -
position;
3155 eraseFile( stream, position, length );
3159 void fileErase(
IN_STRING const char *fileName )
3162 struct stat fstatInfo;
3163 #ifndef USE_EMBEDDED_OS
3164 #if defined( __FreeBSD__ )
3165 struct timeval timeVals[ 2 ];
3166 #elif !( defined( __APPLE__ ) || defined( __FreeBSD__ ) || \
3167 defined( __linux__ ) )
3168 struct utimbuf timeStamp;
3172 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
3179 fileName = bufferToEbcdic( fileNameBuffer, fileName );
3184 status = sFileOpen( &stream, fileName,
3185 FILE_FLAG_READ | FILE_FLAG_WRITE | \
3186 FILE_FLAG_EXCLUSIVE_ACCESS );
3195 if( fstat( stream.fd, &fstatInfo ) == 0 )
3196 eraseFile( &stream, 0, fstatInfo.st_size );
3219 #ifndef USE_EMBEDDED_OS
3220 #if defined( __APPLE__ )
3221 futimes( stream.fd, NULL );
3222 sFileClose( &stream );
3223 #elif defined( __FreeBSD__ )
3224 memset( timeVals, 0,
sizeof(
struct timeval ) * 2 );
3225 futimes( stream.fd, timeVals );
3226 futimes( stream.fd, timeVals );
3227 sFileClose( &stream );
3228 #elif defined( __UCLIBC__ )
3229 sFileClose( &stream );
3230 utimes( fileName, NULL );
3231 #elif defined( __linux__ )
3233 if( futimes( stream.fd, NULL ) < 0 )
3235 sFileClose( &stream );
3236 if( status == ENOSYS )
3237 utimes( fileName, NULL );
3239 sFileClose( &stream );
3240 memset( &timeStamp, 0,
sizeof(
struct utimbuf ) );
3241 utime( fileName, &timeStamp );
3244 sFileClose( &stream );
3251 #if defined( USE_EMBEDDED_OS )
3254 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
3257 IN_BUFFER( fileNameLen )
const char *fileName,
3263 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
3264 assert( ( fileName == NULL && fileNameLen == 0 ) || \
3272 fileNameLen == 0 ) );
3280 return( appendFilename( path, pathMaxLen, pathLen, fileName,
3281 fileNameLen, option ) );
3288 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
3291 IN_BUFFER( fileNameLen )
const char *fileName,
3296 struct passwd *passwd;
3299 char fileNameBuffer[ MAX_PATH_LENGTH + 8 ];
3304 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
3305 assert(
isReadPtr( fileName, fileNameLen ) );
3312 fileNameLen == 0 ) );
3335 fileName = bufferToEbcdic( fileNameBuffer, fileName );
3336 #pragma convlit( suspend )
3339 if( ( passwd = getpwuid( getuid() ) ) == NULL )
3340 return( CRYPT_ERROR_OPEN );
3341 if( ( length = strlen( passwd->pw_dir ) ) > MAX_PATH_LENGTH - 64 )
3342 return( CRYPT_ERROR_OPEN );
3345 #if defined( __APPLE__ )
3346 if( length + 32 >= pathMaxLen )
3349 if( length + 16 >= pathMaxLen )
3352 memcpy( path, passwd->pw_dir, length );
3353 if( path[ length - 1 ] !=
'/' )
3354 path[ length++ ] =
'/';
3355 #if defined( __APPLE__ )
3358 strlcpy_s( path + length, pathMaxLen - length,
3359 "Library/Preferences/cryptlib" );
3361 strlcpy_s( path + length, pathMaxLen - length,
".cryptlib" );
3375 access( path, F_OK ) < 0 && mkdir( path, 0700 ) < 0 )
3376 return( CRYPT_ERROR_OPEN );
3380 #ifndef EBCDIC_CHARS
3382 return( appendFilename( path, pathMaxLen, pathLen, fileName,
3383 fileNameLen, option ) );
3385 status = appendFilenameEBCDIC( path, pathMaxLen, pathLen, fileName,
3386 fileNameLen, option );
3389 ebcdicToAscii( path, path, pathLen );
3390 #pragma convlit( resume )
3403 #elif defined( __VXWORKS__ )
3442 static
int getErrorCode(
const int defaultErrorCode )
3444 const int moduleNo = errno >> 16;
3445 const int errNo = errno & 0xFFFFL;
3472 return( defaultErrorCode );
3487 memset( stream, 0,
sizeof(
STREAM ) );
3489 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
3494 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
3500 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_WRITE )
3505 if( ( stream->fd = creat( fileName, 0600 ) ) == ERROR )
3506 return( getErrorCode( CRYPT_ERROR_OPEN ) );
3514 if( ( stream->fd = open( fileName, mode, 0600 ) ) == ERROR )
3518 return( getErrorCode( CRYPT_ERROR_OPEN ) );
3533 close( stream->fd );
3543 OUT_BUFFER( length, *bytesRead )
void *buffer,
3551 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
3559 if( ( byteCount = read( stream->fd, buffer, length ) ) == ERROR )
3561 *bytesRead = byteCount;
3577 if( write( stream->fd, buffer, length ) != length )
3594 return( ioctl( stream->fd, FIOFLUSH, 0 ) == ERROR && \
3595 ioctl( stream->fd, FIOSYNC, 0 ) == ERROR ? \
3609 if( lseek( stream->fd, position,
SEEK_SET ) == ERROR )
3625 if( ( fd = open( fileName, O_RDWR, 0600 ) ) == ERROR )
3641 static
void eraseFile(
const STREAM *stream,
long position,
long length )
3655 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
3656 int bytesToWrite =
min( length, BUFSIZ * 2 );
3663 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
3664 if( write( stream->fd, buffer, bytesToWrite ) <= bytesToWrite )
3666 length -= bytesToWrite;
3668 ioctl( stream->fd, FIOFLUSH, 0 );
3673 ioctl( stream->fd, FIOTRUNC, position );
3676 ioctl( stream->fd, FIOATTRIBSET, 0 );
3677 ioctl( stream->fd, FIOTIMESET, 0 );
3682 void fileClearToEOF(
const STREAM *stream )
3684 struct stat statStruct;
3694 position = ioctl( stream->fd, FIOWHERE, 0 );
3695 if( ioctl( stream->fd, FIOFSTATGET, (
int ) &statStruct ) != ERROR )
3696 length = statStruct.st_size -
position;
3701 length = ioctl( stream->fd, FIOWHERE, 0 ) -
position;
3702 lseek( stream->fd, position,
SEEK_SET );
3704 eraseFile( stream, position, length );
3708 void fileErase(
IN_STRING const char *fileName )
3711 struct stat statStruct;
3718 status = sFileOpen( &stream, fileName,
3719 FILE_FLAG_READ | FILE_FLAG_WRITE | \
3720 FILE_FLAG_EXCLUSIVE_ACCESS );
3731 if( ioctl( stream.fd, FIOFSTATGET, (
int ) &statStruct ) != ERROR )
3732 length = statStruct.st_size;
3737 length = ioctl( stream.fd, FIOWHERE, 0 );
3740 eraseFile( &stream, 0, length );
3742 sFileClose( &stream );
3751 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
3754 IN_BUFFER( fileNameLen )
const char *fileName,
3760 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
3761 assert(
isReadPtr( fileName, fileNameLen ) );
3768 fileNameLen == 0 ) );
3774 ioDefPathGet( path );
3780 return( appendFilename( path, pathMaxLen, pathLen, fileName,
3781 fileNameLen, option ) );
3790 #elif defined( __WIN32__ ) || defined( __WINCE__ )
3809 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
3810 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
3812 #define FILE_FLAGS ( FILE_FLAG_SEQUENTIAL_SCAN | \
3813 SECURITY_SQOS_PRESENT | SECURITY_ANONYMOUS )
3814 #define FILE_ATTRIBUTES FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
3817 #define FILE_FLAGS 0
3818 #define FILE_ATTRIBUTES 0
3830 #ifndef CSIDL_PERSONAL
3831 #define CSIDL_PERSONAL 0x05
3833 #ifndef CSIDL_APPDATA
3834 #define CSIDL_APPDATA 0x1A
3836 #ifndef CSIDL_FLAG_CREATE
3837 #define CSIDL_FLAG_CREATE 0x8000
3839 #ifndef SHGFP_TYPE_CURRENT
3840 #define SHGFP_TYPE_CURRENT 0
3846 #ifndef SECURITY_LOCAL_SERVICE_RID
3847 #define SECURITY_LOCAL_SERVICE_RID 19
3848 #define SECURITY_NETWORK_SERVICE_RID 20
3859 if( type == SYSVAR_ISWIN95 )
3863 #define getSysVar localGetSysVar
3871 #define TOKEN_BUFFER_SIZE 256
3872 #define SID_BUFFER_SIZE 256
3873 #define UNI_BUFFER_SIZE ( 256 + _MAX_PATH )
3874 #define PATH_BUFFER_SIZE ( _MAX_PATH + 16 )
3879 BYTE sidBuffer[ SID_BUFFER_SIZE + 8 ];
3880 SID *pSid = ( PSID ) sidBuffer;
3881 SID_IDENTIFIER_AUTHORITY identifierAuthority = SECURITY_NT_AUTHORITY;
3883 assert(
isWritePtr( pUserSid,
sizeof( SID ) ) );
3892 InitializeSid( pSid, &identifierAuthority, 1 );
3893 *( GetSidSubAuthority( pSid, 0 ) ) = SECURITY_LOCAL_SYSTEM_RID;
3894 if( EqualSid( pSid, pUserSid ) )
3896 *( GetSidSubAuthority( pSid, 0 ) ) = SECURITY_LOCAL_SERVICE_RID;
3897 if( EqualSid( pSid, pUserSid ) )
3899 *( GetSidSubAuthority( pSid, 0 ) ) = SECURITY_NETWORK_SERVICE_RID;
3900 if( EqualSid( pSid, pUserSid ) )
3907 static
const char *getUncName(
OUT UNIVERSAL_NAME_INFO *nameInfo,
3908 const char *fileName )
3910 typedef DWORD ( WINAPI *WNETGETUNIVERSALNAMEA )( LPCSTR lpLocalPath,
3912 LPDWORD lpBufferSize );
3913 WNETGETUNIVERSALNAMEA pWNetGetUniversalNameA;
3915 DWORD uniBufSize = UNI_BUFFER_SIZE;
3918 assert(
isWritePtr( nameInfo,
sizeof( UNIVERSAL_NAME_INFO ) ) );
3919 assert(
isReadPtr( fileName,
sizeof(
char * ) ) );
3922 memset( nameInfo, 0,
sizeof( UNIVERSAL_NAME_INFO ) );
3930 hMPR = DynamicLoad(
"Mpr.dll" );
3942 pWNetGetUniversalNameA = ( WNETGETUNIVERSALNAMEA ) \
3943 GetProcAddress( hMPR,
"WNetGetUniversalNameA" );
3944 if( pWNetGetUniversalNameA != NULL && \
3945 pWNetGetUniversalNameA( fileName, UNIVERSAL_NAME_INFO_LEVEL,
3946 nameInfo, &uniBufSize ) == NO_ERROR )
3948 DynamicUnload( hMPR );
3950 return( gotUNC ? nameInfo->lpUniversalName : NULL );
3954 static
BOOLEAN checkUserKnown(
IN_BUFFER( fileNameLength )
const char *fileName,
3955 const int fileNameLength )
3958 BYTE uniBuffer[ UNI_BUFFER_SIZE + 8 ];
3959 BYTE tokenBuffer[ TOKEN_BUFFER_SIZE + 8 ];
3960 char pathBuffer[ PATH_BUFFER_SIZE + 8 ];
3961 char nameBuffer[ PATH_BUFFER_SIZE + 8 ];
3962 char domainBuffer[ PATH_BUFFER_SIZE + 8 ];
3963 const char *fileNamePtr = (
char * ) fileName;
3964 UNIVERSAL_NAME_INFO *nameInfo = ( UNIVERSAL_NAME_INFO * ) uniBuffer;
3965 TOKEN_USER *pTokenUser = ( TOKEN_USER * ) tokenBuffer;
3967 DWORD nameBufSize = PATH_BUFFER_SIZE, domainBufSize = PATH_BUFFER_SIZE;
3969 int fileNamePtrLength = fileNameLength, serverNameLength,
length;
3971 assert(
isReadPtr( fileName, fileNameLength ) );
3973 static_assert(
sizeof( UNIVERSAL_NAME_INFO ) + _MAX_PATH <= UNI_BUFFER_SIZE, \
3974 "UNC buffer size" );
3976 REQUIRES_B( fileNameLength > 0 && fileNameLength < _MAX_PATH );
3994 length = GetFullPathName( fileNamePtr, PATH_BUFFER_SIZE, pathBuffer, NULL );
3995 if( length > 0 && length < PATH_BUFFER_SIZE )
3997 fileNamePtr = pathBuffer;
3998 fileNamePtrLength =
length;
4003 if( fileNamePtrLength <= 2 )
4012 if( fileNamePtr[ 1 ] ==
':' )
4014 char drive[ 8 + 8 ];
4016 memcpy( drive, fileNamePtr, 2 );
4018 if( GetDriveType( drive ) != DRIVE_REMOTE )
4023 isMappedDrive =
TRUE;
4029 if( memcmp( fileNamePtr,
"\\\\", 2 ) )
4041 fileNamePtr = getUncName( nameInfo, fileNamePtr );
4042 if( fileNamePtr == NULL )
4046 assert( !memcmp( fileNamePtr,
"\\\\", 2 ) );
4051 for( serverNameLength = 2; \
4052 serverNameLength < fileNamePtrLength && \
4053 fileNamePtr[ serverNameLength ] !=
'\\'; \
4054 serverNameLength++ );
4055 if( serverNameLength <= 0 || serverNameLength >= PATH_BUFFER_SIZE - 2 )
4060 memmove( pathBuffer, fileNamePtr, serverNameLength );
4061 strlcpy_s( pathBuffer + serverNameLength,
4062 PATH_BUFFER_SIZE - serverNameLength,
"\\" );
4065 if( OpenThreadToken( GetCurrentThread(), TOKEN_QUERY,
FALSE, &hToken ) || \
4066 OpenProcessToken( GetCurrentProcess(), TOKEN_QUERY, &hToken ) )
4070 tokenOK = GetTokenInformation( hToken, TokenUser, pTokenUser,
4071 TOKEN_BUFFER_SIZE, &cbTokenUser );
4072 CloseHandle( hToken );
4079 if( isSpecialSID( pTokenUser->User.Sid ) )
4092 if( !LookupAccountSid( pathBuffer, pTokenUser->User.Sid,
4093 nameBuffer, &nameBufSize,
4094 domainBuffer, &domainBufSize, &eUse ) && \
4095 GetLastError() == ERROR_NONE_MAPPED )
4115 const char *fileNamePtr =
fileName;
4117 wchar_t fileNameBuffer[ _MAX_PATH + 16 ], *fileNamePtr = fileNameBuffer;
4119 void *aclInfo = NULL;
4128 memset( stream, 0,
sizeof(
STREAM ) );
4130 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
4135 status = asciiToUnicode( fileNameBuffer, _MAX_PATH, fileName,
4136 strlen( fileName ) + 1 );
4138 return( CRYPT_ERROR_OPEN );
4158 if( !memcmp( fileNamePtr,
"\\\\", 2 ) )
4160 const int length = strlen( (
char * ) fileNamePtr );
4162 if( length >= 4 && !memcmp( fileNamePtr,
"\\\\?\\", 4 ) )
4163 return( CRYPT_ERROR_OPEN );
4167 if( !memcmp( fileNamePtr, L
"\\\\", 4 ) )
4169 const int length = wcslen( (
wchar_t * ) fileNamePtr );
4171 if( length >= 8 && !memcmp( fileNamePtr, L
"\\\\?\\", 8 ) )
4172 return( CRYPT_ERROR_OPEN );
4202 ( mode & FILE_FLAG_WRITE ) && ( mode & FILE_FLAG_PRIVATE ) && \
4203 checkUserKnown( fileNamePtr, strlen( fileNamePtr ) ) && \
4204 ( aclInfo = initACLInfo( FILE_GENERIC_READ | \
4205 FILE_GENERIC_WRITE ) ) == NULL )
4206 return( CRYPT_ERROR_OPEN );
4221 hFile = CreateFile( fileNamePtr, GENERIC_READ, FILE_SHARE_READ, NULL,
4222 OPEN_EXISTING, FILE_FLAGS, NULL );
4223 if( hFile != INVALID_HANDLE_VALUE )
4225 const DWORD type = GetFileType( hFile );
4227 CloseHandle( hFile );
4228 if( type != FILE_TYPE_DISK )
4230 if( aclInfo != NULL )
4231 freeACLInfo( aclInfo );
4232 return( CRYPT_ERROR_OPEN );
4239 uErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
4241 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_WRITE )
4255 fSuccess = DeleteFile( fileNamePtr );
4256 if( !fSuccess && GetLastError() == ERROR_ACCESS_DENIED )
4258 if( aclInfo != NULL )
4259 freeACLInfo( aclInfo );
4262 stream->hFile = CreateFile( fileNamePtr, GENERIC_READ | GENERIC_WRITE, 0,
4263 getACLInfo( aclInfo ), CREATE_ALWAYS,
4264 FILE_ATTRIBUTES | FILE_FLAGS, NULL );
4265 if( stream->hFile != INVALID_HANDLE_VALUE && \
4266 GetLastError() == ERROR_ALREADY_EXISTS )
4271 CloseHandle( stream->hFile );
4272 DeleteFile( fileNamePtr );
4273 stream->hFile = INVALID_HANDLE_VALUE;
4279 GENERIC_READ : GENERIC_READ | GENERIC_WRITE;
4281 0 : FILE_SHARE_READ;
4283 stream->hFile = CreateFile( fileNamePtr, openMode, shareMode, NULL,
4284 OPEN_EXISTING, FILE_FLAGS, NULL );
4286 if( stream->hFile != INVALID_HANDLE_VALUE && \
4287 GetFileType( stream->hFile ) != FILE_TYPE_DISK )
4293 CloseHandle( stream->hFile );
4294 if( aclInfo != NULL )
4295 freeACLInfo( aclInfo );
4296 SetErrorMode( uErrorMode );
4297 return( CRYPT_ERROR_OPEN );
4302 SetErrorMode( uErrorMode );
4304 if( stream->hFile == INVALID_HANDLE_VALUE )
4308 switch( GetLastError() )
4310 case ERROR_FILE_NOT_FOUND:
4311 case ERROR_PATH_NOT_FOUND:
4315 case ERROR_ACCESS_DENIED:
4336 if( aclInfo != NULL )
4337 freeACLInfo( aclInfo );
4349 CloseHandle( stream->hFile );
4359 OUT_BUFFER( length, *bytesRead )
void *buffer,
4367 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
4375 if( !ReadFile( stream->hFile, buffer, length, &byteCount, NULL ) )
4377 *bytesRead = byteCount;
4395 if( !WriteFile( stream->hFile, buffer, length, &bytesWritten, NULL ) || \
4396 (
int ) bytesWritten != length )
4424 if( SetFilePointer( stream->hFile, position, NULL,
4425 FILE_BEGIN ) == 0xFFFFFFFF )
4437 wchar_t fileNameBuffer[ _MAX_PATH + 16 ], *fileNamePtr = fileNameBuffer;
4440 const char *fileNamePtr =
fileName;
4447 status = asciiToUnicode( fileNameBuffer, _MAX_PATH, fileName,
4448 strlen( fileName ) + 1 );
4459 hFile = CreateFile( fileNamePtr, GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
4460 FILE_ATTRIBUTE_NORMAL, NULL );
4461 if( hFile == INVALID_HANDLE_VALUE )
4465 return( ( GetLastError() == ERROR_ACCESS_DENIED ) ?
TRUE :
FALSE );
4467 CloseHandle( hFile );
4477 static
void eraseFile(
const STREAM *stream,
long position,
long length )
4491 BYTE buffer[ 1024 + 8 ];
4493 int bytesToWrite =
min( length, 1024 );
4500 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
4501 WriteFile( stream->hFile, buffer, bytesToWrite, &bytesWritten, NULL );
4502 length -= bytesToWrite;
4513 SetFilePointer( stream->hFile, position, NULL, FILE_BEGIN );
4514 SetEndOfFile( stream->hFile );
4516 SetFileTime( stream->hFile, 0, 0, 0 );
4517 FlushFileBuffers( stream->hFile );
4521 void fileClearToEOF(
const STREAM *stream )
4530 if( ( position = SetFilePointer( stream->hFile, 0, NULL,
4531 FILE_CURRENT ) ) == 0xFFFFFFFF )
4533 length = GetFileSize( stream->hFile, NULL ) -
position;
4536 eraseFile( stream, position, length );
4540 void fileErase(
IN_STRING const char *fileName )
4544 wchar_t fileNameBuffer[ _MAX_PATH + 16 ], *fileNamePtr = fileNameBuffer;
4546 const char *fileNamePtr =
fileName;
4554 status = asciiToUnicode( fileNameBuffer, _MAX_PATH, fileName,
4555 strlen( fileName ) + 1 );
4562 status = sFileOpen( &stream, fileName,
4563 FILE_FLAG_READ | FILE_FLAG_WRITE | \
4564 FILE_FLAG_EXCLUSIVE_ACCESS );
4568 DeleteFile( fileNamePtr );
4571 eraseFile( &stream, 0, GetFileSize( stream.hFile, NULL ) );
4572 sFileClose( &stream );
4573 DeleteFile( fileNamePtr );
4578 #if defined( __WIN32__ )
4581 #define WIN_DEFAULT_USER_HANDLE IntToPtr( -1 )
4583 #define WIN_DEFAULT_USER_HANDLE ( HANDLE ) -1
4587 static
int getFolderPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
4591 typedef HRESULT ( WINAPI *SHGETFOLDERPATH )( HWND hwndOwner,
4592 int nFolder,
HANDLE hToken,
4594 SHGETFOLDERPATH pSHGetFolderPath;
4595 const int osMajorVersion =
getSysVar( SYSVAR_OSMAJOR );
4599 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
4604 memset( path, 0,
min( 16, pathMaxLen ) );
4611 REQUIRES( pathMaxLen >= MAX_PATH );
4620 if( osMajorVersion <= 4 )
4622 HINSTANCE hComCtl32, hSHFolder;
4642 hComCtl32 = DynamicLoad(
"ComCtl32.dll" );
4643 if( hComCtl32 != NULL )
4645 if( ( hSHFolder = DynamicLoad(
"SHFolder.dll" ) ) != NULL )
4647 pSHGetFolderPath = ( SHGETFOLDERPATH ) \
4648 GetProcAddress( hSHFolder,
"SHGetFolderPathA" );
4649 if( pSHGetFolderPath != NULL && \
4650 pSHGetFolderPath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
4651 NULL, SHGFP_TYPE_CURRENT, path ) == S_OK )
4653 DynamicUnload( hSHFolder );
4655 DynamicUnload( hComCtl32 );
4660 const int osMinorVersion =
getSysVar( SYSVAR_OSMINOR );
4661 const BOOLEAN isXPOrNewer = ( osMajorVersion > 5 || \
4662 ( osMajorVersion == 5 && \
4664 char defaultUserPath[ MAX_PATH + 16 ];
4688 hShell32 = DynamicLoad(
"Shell32.dll" );
4689 if( hShell32 != NULL )
4691 pSHGetFolderPath = ( SHGETFOLDERPATH ) \
4692 GetProcAddress( hShell32,
"SHGetFolderPathA" );
4693 if( pSHGetFolderPath != NULL )
4695 if( pSHGetFolderPath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
4696 NULL, SHGFP_TYPE_CURRENT, path ) == S_OK )
4698 if( gotPath && isXPOrNewer && \
4699 pSHGetFolderPath( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
4700 WIN_DEFAULT_USER_HANDLE,
4702 defaultUserPath ) == S_OK )
4704 if( !strcmp( path, defaultUserPath ) )
4705 isDefaultUserPath =
TRUE;
4708 DynamicUnload( hShell32 );
4710 if( isDefaultUserPath )
4715 DEBUG_PRINT((
"No Windows user profile available, is this "
4716 "application running as a service or using "
4717 "impersonation?" ));
4718 return( CRYPT_ERROR_OPEN );
4723 *pathLen = strlen( path );
4733 if( !GetWindowsDirectory( path, pathMaxLen - 8 ) )
4735 *pathLen = strlen( path );
4749 if( !GetWindowsDirectory( path, pathMaxLen - 8 ) )
4751 *pathLen = strlen( path );
4758 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
4761 IN_BUFFER( fileNameLen )
const char *fileName,
4766 #if defined( __WIN32__ )
4767 #if defined( __BORLANDC__ ) && ( __BORLANDC__ < 0x550 )
4768 #define HRESULT DWORD
4770 char *pathPtr =
path;
4772 #elif defined( __WINCE__ )
4773 wchar_t pathBuffer[ _MAX_PATH + 8 ], *pathPtr = pathBuffer;
4779 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
4788 fileNameLen == 0 ) );
4793 #if defined( __WIN32__ )
4795 status = getFolderPath( path, pathMaxLen, &length );
4798 if( length + 16 >= pathMaxLen )
4800 strlcpy_s( pathPtr + length, pathMaxLen - length,
"\\cryptlib" );
4801 #elif defined( __WINCE__ )
4802 if( SHGetSpecialFolderPath( NULL, pathPtr, CSIDL_APPDATA,
TRUE ) || \
4803 SHGetSpecialFolderPath( NULL, pathPtr, CSIDL_PERSONAL,
TRUE ) )
4813 wcscpy( pathPtr, L
"\\Windows" );
4815 length = wcslen( pathPtr );
4821 REQUIRES( ( length + 16 ) *
sizeof(
wchar_t ) <= _MAX_PATH && \
4822 length + 16 <= pathMaxLen );
4824 wcscat( pathPtr, L
"\\cryptlib" );
4830 GetFileAttributes( pathPtr ) == 0xFFFFFFFFUL )
4832 void *aclInfo = NULL;
4836 ( aclInfo = initACLInfo( FILE_ALL_ACCESS ) ) == NULL )
4839 retVal = CreateDirectory( pathPtr, getACLInfo( aclInfo ) );
4840 freeACLInfo( aclInfo );
4842 return( CRYPT_ERROR_OPEN );
4844 #if defined( __WINCE__ )
4845 unicodeToAscii( path, pathMaxLen, pathPtr, wcslen( pathPtr ) + 1 );
4850 return( appendFilename( path, pathMaxLen, pathLen, fileName,
4851 fileNameLen, option ) );
4860 #elif defined( __XMK__ )
4868 static const int modes[] = { MFS_MODE_READ, MFS_MODE_READ,
4869 MFS_MODE_CREATE, MFS_MODE_WRITE };
4875 REQUIRE( mode != 0 );
4878 memset( stream, 0,
sizeof(
STREAM ) );
4880 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
4885 if( ( mode & FILE_FLAG_READ ) && mfs_exists_file( fileName ) != 1 )
4889 if( ( stream->fd = mfs_file_open( fileName, openMode ) ) < 0 )
4890 return( CRYPT_ERROR_OPEN );
4903 mfs_file_close( stream->fd );
4913 OUT_BUFFER( length, *bytesRead )
void *buffer,
4921 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
4929 if( ( byteCount = mfs_file_read( stream->fd, buffer, length ) ) < 0 )
4931 *bytesRead = byteCount;
4947 if( mfs_file_write( stream->fd, buffer, length ) < 0 )
4985 if( mfs_file_lseek( stream->fd, position, MFS_SEEK_SET ) < 0 )
5010 void fileClearToEOF(
const STREAM *stream )
5020 void fileErase(
IN_STRING const char *fileName )
5027 mfs_delete_file( fileName );
5033 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
5036 IN_BUFFER( fileNameLen )
const char *fileName,
5042 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
5043 assert(
isReadPtr( fileName, fileNameLen ) );
5050 fileNameLen == 0 ) );
5056 strlcpy_s( path, pathMaxLen,
"/cryptlib/" );
5063 if( mfs_create_dir( path ) <= 0 )
5064 return( CRYPT_ERROR_OPEN );
5068 return( appendFilename( path, pathMaxLen, pathLen, fileName,
5069 fileNameLen, option ) );
5083 #if defined( __STDC__ ) && ( __BORLANDC__ == 0x410 )
5084 #define fileno( filePtr ) ( ( filePtr )->fd )
5091 #if defined( __MSDOS16__ ) || defined( __OS2__ ) || defined( __WIN16__ )
5103 #if defined( __WATCOMC__ ) && defined( __DOS__ )
5107 unsigned short ft_tsec : 5;
5108 unsigned short ft_min : 6;
5109 unsigned short ft_hour : 5;
5110 unsigned short ft_day : 5;
5111 unsigned short ft_month : 4;
5112 unsigned short ft_year : 7;
5130 const char *openMode;
5138 memset( stream, 0,
sizeof(
STREAM ) );
5140 if( ( mode & FILE_FLAG_RW_MASK ) == FILE_FLAG_READ )
5146 if( ( mode & FILE_FLAG_WRITE ) && fileReadonly( fileName ) )
5150 stream->filePtr = fopen( fileName, openMode );
5151 #if defined( __MSDOS16__ ) || defined( __WIN16__ ) || defined( __WINCE__ ) || \
5152 defined( __OS2__ ) || defined( __SYMBIAN32__ )
5153 if( stream->filePtr == NULL )
5157 return( ( access( fileName, 0 ) < 0 ) ? \
5160 #elif defined( __TANDEMNSK__ )
5161 if( stream->filePtr == NULL )
5163 return( ( errno == ENOENT ) ? \
5167 #error Need to add file open error-handling
5181 fclose( stream->filePtr );
5191 OUT_BUFFER( length, *bytesRead )
void *buffer,
5199 assert(
isWritePtr( bytesRead,
sizeof(
int ) ) );
5207 if( ( byteCount = fread( buffer, 1, length, stream->filePtr ) ) < length && \
5208 ( byteCount < 0 || ferror( stream->filePtr ) ) )
5210 *bytesRead = byteCount;
5226 if( fwrite( buffer, 1, length, stream->filePtr ) != length )
5253 if( fseek( stream->filePtr, position,
SEEK_SET ) )
5263 #if defined( __MSDOS16__ ) || defined( __WIN16__ ) || defined( __OS2__ ) || \
5264 defined( __SYMBIAN32__ ) || defined( __BEOS__ )
5265 if( access( fileName,
W_OK ) < 0 && errno != ENOENT )
5267 #elif defined( __TANDEMNSK__ )
5274 if( errno == EACCES )
5280 #error Need to add file accessibility call
5290 static void eraseFile(
const STREAM *stream,
long position,
long length )
5292 int fileHandle = fileno( stream->
filePtr );
5306 BYTE buffer[ ( BUFSIZ * 2 ) + 8 ];
5307 int bytesToWrite =
min( length, BUFSIZ * 2 );
5314 &msgData, CRYPT_IATTRIBUTE_RANDOM_NONCE );
5315 if( fwrite( buffer, 1, bytesToWrite, stream->
filePtr ) == 0 )
5317 length -= bytesToWrite;
5324 #if defined( __AMIGA__ )
5325 SetFileSize( fileHandle, OFFSET_BEGINNING, position );
5326 #elif defined( __MSDOS16__ ) || defined( __MSDOS32__ )
5327 chsize( fileHandle, position );
5328 #elif defined( __OS2__ )
5329 DosSetFileSize( fileHandle, position );
5330 #elif defined( __WIN16__ )
5331 _chsize( fileHandle, position );
5335 #if defined( __MSDOS16__ ) || defined( __MSDOS32__ )
5336 struct ftime fileTime;
5339 #if defined( __MSDOS16__ ) || defined( __MSDOS32__ )
5340 memset( &fileTime, 0,
sizeof(
struct ftime ) );
5341 #if defined( __WATCOMC__ )
5342 _dos_setftime( fileHandle, \
5343 *( (
unsigned short * ) &fileTime + 1 ), \
5344 *( (
unsigned short * ) &fileTime ) );
5346 setftime( fileHandle, &fileTime );
5353 void fileClearToEOF(
const STREAM *stream )
5362 position = ftell( stream->
filePtr );
5366 eraseFile( stream, position, length );
5370 void fileErase(
IN_STRING const char *fileName )
5373 #if defined( __AMIGA__ )
5374 struct DateStamp dateStamp;
5375 #elif defined( __OS2__ )
5377 #elif defined( __WIN16__ )
5386 status = sFileOpen( &stream, fileName,
5387 FILE_FLAG_READ | FILE_FLAG_WRITE | \
5388 FILE_FLAG_EXCLUSIVE_ACCESS );
5398 length = ( int ) ftell( stream.
filePtr );
5400 eraseFile( &stream, 0, length );
5404 sFileClose( &stream );
5405 #if defined( __AMIGA__ )
5406 memset( dateStamp, 0,
sizeof(
struct DateStamp ) );
5407 SetFileDate( fileName, &dateStamp );
5408 #elif defined( __OS2__ )
5409 DosQueryPathInfo( ( PSZ ) fileName, FIL_STANDARD, &info,
sizeof( info ) );
5410 memset( &info.fdateLastWrite, 0,
sizeof( info.fdateLastWrite ) );
5411 memset( &info.ftimeLastWrite, 0,
sizeof( info.ftimeLastWrite ) );
5412 memset( &info.fdateLastAccess, 0,
sizeof( info.fdateLastAccess ) );
5413 memset( &info.ftimeLastAccess, 0,
sizeof( info.ftimeLastAccess ) );
5414 memset( &info.fdateCreation, 0,
sizeof( info.fdateCreation ) );
5415 memset( &info.ftimeCreation, 0,
sizeof( info.ftimeCreation ) );
5416 DosSetPathInfo( ( PSZ ) fileName, FIL_STANDARD, &info,
sizeof( info ), 0 );
5417 #elif defined( __WIN16__ )
5420 hFile = _lcreat( fileName, 0 );
5421 if( hFile != HFILE_ERROR )
5432 int fileBuildCryptlibPath(
OUT_BUFFER( pathMaxLen, *pathLen )
char *path,
5435 IN_BUFFER( fileNameLen )
const char *fileName,
5440 #if defined( __OS2__ )
5441 ULONG aulSysInfo[ 1 ] = { 0 };
5442 #elif defined( __WIN16__ )
5447 assert(
isWritePtr( pathLen,
sizeof(
int ) ) );
5448 assert(
isReadPtr( fileName, fileNameLen ) );
5455 fileNameLen == 0 ) );
5461 #if defined( __MSDOS__ )
5462 strlcpy_s( path, pathMaxLen,
"c:/dos/" );
5463 return( appendFilename( path, pathMaxLen, pathLen, fileName,
5464 fileNameLen, option ) );
5465 #elif defined( __WIN16__ )
5466 GetWindowsDirectory( path, pathMaxLen - 32 );
5467 strlcat_s( path, pathMaxLen,
"\\cryptlib" );
5474 !_mkdir( path ) && ( errno != EACCES ) )
5475 return( CRYPT_ERROR_OPEN );
5479 return( appendFilename( path, pathMaxLen, pathLen, fileName,
5480 fileNameLen, option ) );
5481 #elif defined( __OS2__ )
5482 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, ( PVOID ) aulSysInfo,
5484 if( *aulSysInfo == 0 )
5485 return( CRYPT_ERROR_OPEN );
5486 path[ 0 ] = *aulSysInfo +
'A' - 1;
5487 strlcpy_s( path + 1, pathMaxLen - 1,
":\\OS2\\" );
5488 return( appendFilename( path, pathMaxLen, pathLen, fileName,
5489 fileNameLen, option ) );
5490 #elif defined( __TANDEMNSK__ )
5491 strlcpy_s( path, pathMaxLen,
"$system.system." );
5493 strlcat_s( path, pathMaxLen,
"randseed" );
5495 strlcat_s( path, pathMaxLen, fileName );
5497 #elif defined( __SYMBIAN32__ )
5498 strlcpy_s( path, pathMaxLen,
"C:\\SYSTEM\\DATA\\" );
5499 return( appendFilename( path, pathMaxLen, pathLen, fileName,
5500 fileNameLen, option ) );
5502 #error Need to add function to build the config file path
5504 return( CRYPT_ERROR_OPEN );