]>
git.saurik.com Git - apple/security.git/blob - SecurityServer/MacYarrow/YarrowServer/entropyFileOS9.c
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
22 Contains: Module to maintain MacYarrow's entropy file.
24 Written by: Doug Mitchell
26 Copyright: (c) 2000 by Apple Computer, Inc., all rights reserved.
28 Change History (most recent first):
34 #include "entropyFile.h"
39 #include <Script.h> // for smSystemScript
42 * FIXME - for debugging, we put the entropy file the current user's
43 * preferences folder. For the real thing, we should either put it in
44 * System preferences or use UNIX I/O to specify some other path.
47 #define ENTROPY_FOLDER kPreferencesFolderType
49 #define ENTROPY_FOLDER kSystemPreferencesFolderType
51 #define ENTROPY_FILE_NAME "\pSystem Entropy"
52 #define ENTROPY_FILE_CREATOR 'yarw'
53 #define ENTROPY_FILE_TYPE 'ENTR'
56 * Open/create entropy file. fnfErr returned if doCreate is false and
57 * the file doesn't exist.
59 static OSErr
openEntropyFile(
61 Boolean writeAccess
, // required if doCreate true
62 short *refNum
) // RETURNED
70 if(doCreate
&& !writeAccess
) {
74 ortn
= FindFolder(kOnSystemDisk
,
80 errorLog1("openEntropyFile: FindFolder returned %d\n", (int)ortn
);
83 ortn
= FSMakeFSSpec(vRefNum
, dirID
, ENTROPY_FILE_NAME
, &fsp
);
95 errorLog1("openEntropyFile: FSMakeFSSpec returned %d\n", (int)ortn
);
99 if(doCreate
&& (ortn
== fnfErr
)) {
101 ortn
= FSpCreate(&fsp
,
102 ENTROPY_FILE_CREATOR
,
106 errorLog1("openEntropyFile: FSpCreate returned %d\n", (int)ortn
);
110 /* fixme - set FInfo.fdFlags.kIsInvisible? */
113 /* open it in any case */
114 perm
= (writeAccess
? fsRdWrPerm
: fsRdPerm
);
115 ortn
= FSpOpenDF(&fsp
, perm
, refNum
);
117 errorLog1("openEntropyFile: FSpOpenDF returned %d\n", (int)ortn
);
123 * Write specified data to entropy file. A new file will be created
124 * if none exists. Data will be appended to possible existing data
125 * if append is true, otherwise the file's data is replaced with
128 OSErr
writeEntropyFile(
136 long actLength
= numBytes
;
138 ortn
= openEntropyFile(true, true, &refNum
);
143 ortn
= GetEOF(refNum
, &eof
);
150 ortn
= SetEOF(refNum
, 0);
156 ortn
= SetFPos(refNum
, fsFromStart
, eof
);
160 ortn
= FSWrite(refNum
, &actLength
, bytes
);
161 if((ortn
== noErr
) && (actLength
!= numBytes
)) {
162 errorLog0("writeEntropyFile: short write\n");
170 * Read data from entropy file.
172 OSErr
readEntropyFile(
174 UInt32 numBytes
, // max # of bytes to read
175 UInt32
*actualBytes
) // RETURNED - number of bytes actually read
179 long actLength
= numBytes
;
181 ortn
= openEntropyFile(false, false, &refNum
);
185 ortn
= FSRead(refNum
, &actLength
, bytes
);
186 *actualBytes
= actLength
;